您的位置:首页 > 其它

234D-cinema 水题被卡

2012-10-16 22:11 113 查看
查错的方法难道只有不断试数据了吗

10 4

2 3 4 1

5

aa

3

1 2 0

bb

2

1 0

cc

4

1 2 3 0

dd

3

0 0 0

ee

2

1 0

特判:只有一个可能超过最坏情况下的最大值,它的答案为0,不是2

可能的数量等于k,必为0

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define N 110
int n,m,k;
int ans
,favor
;
int best
,worst
;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
while(scanf("%d%d",&m,&k)!=EOF)
{
int t;memset(favor,0,sizeof(favor));
for(int i=1;i<=k;++i)
scanf("%d",&t),favor[t]=1;
scanf("%d",&n);char temp[20];
int d,zeros,w_ma=-1,b_ma=-1;
memset(worst,0,sizeof(worst));
memset(best,0,sizeof(best));
for(int i=1;i<=n;++i)
{
scanf("%s",temp);
scanf("%d",&d);
zeros=0;
for(int j=1;j<=d;++j)
{
scanf("%d",&t);
if(favor[t])
worst[i]++,best[i]++;
if(t==0)
{
zeros++;
best[i]++;
}
}
if(zeros-((m-k)-(d-zeros-worst[i]))>0)
worst[i]+=zeros-((m-k)-(d-zeros-worst[i]));

best[i]=best[i]>k?k:best[i];
if(w_ma<worst[i])
w_ma=worst[i];
if(b_ma<best[i])
b_ma=best[i];
}
int flag=0;
for(int i=1;i<=n;++i)
{
if(best[i]>=w_ma)
ans[i]=2;
else ans[i]=1;
if(w_ma==b_ma&&worst[i]==w_ma)
ans[i]=0;
if(worst[i]==k)
ans[i]=0;
if(best[i]>w_ma)
flag++;
}
for(int i=1;i<=n;++i)
{
if(flag==1&&worst[i]>=w_ma&&best[i]>w_ma)
ans[i]=0;
printf("%d\n",ans[i]);
}
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: