A:Cooking Competition ZOJ 2958
题目大意:题不难。但首先要理解题意。一共有四种类型的反馈。输入的那n个数,代表的是第几种反馈。用两个数组储存,这四种类型分别对Kobayashi and Tohru这两人的反馈结果,然后遇到哪种反馈,就加上反馈结果。最初两人都是0,比较最后的值。
代码如下:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int a[5]={0,1,0,1,-1};//注意a[0],b[0]都赋值为0//方便下方对数组的使用
int b[5]={0,0,1,1,-1};
int main(){
int T;
int n,m;
while(scanf("%d",&T)!=EOF){
while(T--){
int sum1=0;int sum2=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&m);
sum1+=a[m];
sum2+=b[m];
}
if(sum1==sum2)cout<<"Draw"<<endl;
else if(sum1>sum2)cout<<"Kobayashi"<<endl;
else cout<<"Tohru"<<endl;
}
}
return 0;
}
D:Let's Chat ZOJ 3961
题目大意:AB两人互发信息,只有两人连续m天都在互发信息时,两人的友谊点才可以加1.问n天时,两人的友谊点是多少。
输入n m x y,x代表,接下来的x行,是A向B发信息的时间段。接下来的y行,是B向A发信息的时间段。
思路:首先要找到AB相互发消息公共的时间段,再判断,这个时间段是否满足大于m天。
对于A给B发信息的这几个时间段,若不满足长度大于等于m,则继续下一段的输入,如满足,则将这一时间段统计下来。
同理,对于B给A发信息也是。
最后,对统计的这两个数组进行比较。统计满足长度为m天的个数。
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
struct node{
int st,ed;
};
node p[110];
node s[110];
node Q[110];
int n,m,x,y;
int f,e;
int main(){
int T;
while(scanf("%d",&T)!=EOF){
while(T--){
int cntx=0;int cnty=0;
scanf("%d%d%d%d",&n,&m,&x,&y);
//存x
for(int i=0;i<x;i++){
cin>>f>>e;
if(e-f+1<m)continue;
else{
p[cntx].st=f;
p[cntx].ed=e;
cntx++;
}
}
//存y
for(int i=0;i<y;i++){
cin>>f>>e;
if(e-f+1<m)continue;
else{
s[cnty].st=f;
s[cnty].ed=e;
cnty++;
}
}
//比较x y
int cnt=0;
for(int i=0;i<cntx;i++)
for(int j=0;j<cnty;j++){
//if(p[i].ed<s[j].st || p[i].st>s[j].ed) break;
if(p[i].ed<s[j].st) break;//注意这里
if(p[i].st>s[j].ed) continue;
Q[cnt].st=max(p[i].st,s[j].st);
Q[cnt].ed=min(p[i].ed,s[j].ed);
cnt++;
}
int sum=0;
for(int i=0;i<cnt;i++){
int t=Q[i].ed-Q[i].st+1;
if(t>=m)sum+=t-(m-1);
}
cout<<sum<<endl;
}
}
return 0;
}