| ||||||||||
| 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 | |||||||||
求高手赐教,我的程序到底又什么问题,头炸了。。。我设置的思想是用left,right数组分别记录当前这一记录的左右天平中的币号,然后如果是=就将对应的号在true数组中的位置置为1,否则将不在当前记录中的coin置成1,最后根据true中0的个数,如果不是1就是不能确定false coin的情况,否则输出对应的号码就是false coin,自己各种测试都是可以的,但是不知道为什么提交总是错的,希望大侠赐教
#include <stdio.h>
main()
{ int N,K,curnum,*true,i,*left,*right,*true2,j,h,p,pk,flg=0,bb,kk=0;
char res;
scanf("%d%d",&N,&K);
true=(int *)malloc(N*sizeof(int));
true2=(int *)malloc(N*sizeof(int));
left=(int *)malloc((N/2+1)*sizeof(int));
right=(int *)malloc((N/2+1)*sizeof(int));
for (i=0;i<N ;i++ ){true[i]=0;
true2[i]=1;/*init*/
}
for (i=0;i<K ; i++)
{
scanf("%d",&curnum);
for (j=0;j<curnum ;j++ )
scanf("%d",&left[j]);
for (j=0;j<curnum ;j++ )
scanf("%d",&right[j]);
scanf("%1s",&res);
switch(res)
{ case '=' : for (h=0;h<curnum ;h++ )
{
p=left[h];
true[p-1]=1;
p=right[h];
true[p-1]=1;
}
break;
case '<':
case '>' : for (h=0;h<curnum ;h++ )
{
p=left[h];
true2[p-1]=0;
p=right[h];
true2[p-1]=0;
}
kk=1;
break;
}
if(kk){
for (bb=0;bb<N;bb++)
{
if(true2[bb]) true[bb]=1;
else true2[bb]=1;
}
kk=0;
}
}
for (h=0;h<N ; h++)if(!true[h]){pk=h;
flg++;
}
if(flg!=1)printf("%d\n",0);
else printf("%d\n",pk+1);
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator