代理服务器 清华考研复试上机
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
map<string,bool> agent;
void reset(){
for(auto it=agent.begin();it!=agent.end();it++)
(*it).second=true;
}
bool all_false(){
for(auto it=agent.begin();it!=agent.end();it++){
if((*it).second==true) return false;
}
return true;
}
int main(){
int n,m;
while(cin>>n){
string tmp;
for(int i=0;i<n;i++){
cin>>tmp;
agent[tmp]=true;
}
cin>>m;
int cnt=0;
for(int i=0;i<m;i++){
cin>>tmp;
if(agent.count(tmp)==1){
agent[tmp]=false;
if(all_false()==true){
reset();
agent[tmp]=false;
cnt++;
}
}
}
if(agent.size()==1&&cnt!=0) cout<<-1<<endl;
else cout<<cnt<<endl;
}
return 0;
}
观看节目数最多的方案
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=100;
struct Program{
int startTime;
int endTime;
}arr[MAXN];
bool Compare(Program x,Program y){
return x.endTime<y.endTime;
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
if(n==0) break;
for(int i=0;i<n;i++){
scanf("%d%d",&arr[i].startTime,&arr[i].endTime);
}
sort(arr,arr+n,Compare);
int currentTime=0;
int answer=0;
for(int i=0;i<n;i++){
if(currentTime<=arr[i].startTime){
currentTime=arr[i].endTime;
answer++;
}
}
printf("%d\n",answer);
}
return 0;
}
|