| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这道题太bt了WA了我一整天。。。。一道程序害的我好像做了两道题,早上的程序到下午的时候,被我全删了。。。。汗汗。。。
#include <stdio.h>
#include <string.h>
int id[105][1005],k;
char ch[105];
int falsecoin(int *a)
{
int i,j,s1=0,s2=0;
for(i=0;i<k;i++)
{
s1=0;
s2=0;
for(j=1;j<=id[i][0];j++)
s1+=a[id[i][j]];
for(j=id[i][0]+1;j<=2*id[i][0];j++)
s2+=a[id[i][j]];
if(s1==s2&&ch[i]=='='||s1>s2&&ch[i]=='>'||s1<s2&&ch[i]=='<')
continue;
else
return 1;
}
return 0;
}
int main()
{
int n,i,j,flag,w,l1,l2;
int a[1005],b[1005];
// freopen("duo1029.txt","r",stdin);
while(scanf("%d%d",&n,&k)==2)
{
for(j=0;j<k;j++)
{
for(i=1,scanf("%d",&id[j][0]);i<=2*id[j][0];i++)
scanf("%d",&id[j][i]);
getchar();
ch[j]=getchar();
}
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(i=1;i<=n;i++)
a[i]=2;
flag=0;
for(i=0;i<k;i++)
if(ch[i]=='=')
{
for(j=1;j<=2*id[i][0];j++)
{
b[id[i][j]]=2;//作为dp的一个判断,当出现'='时,所有的硬币都为真.
}
}
for(i=1;i<=n;i++)//遍历所有的硬币。1表示轻,2表示正常,3表示重了
if(!b[i])
{
a[i]=1;
l1=falsecoin(a);
a[i]=3;
l2=falsecoin(a);
if(!l1||!l2)
{
flag++;
w=i;
}
a[i]=2;
}
if(flag==1)
printf("%d\n",w);
else
printf("0\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator