Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

0ms

Posted by Web_Board at 2008-12-25 16:58:22 on Problem 1029
In Reply To:蛮力法,32ms 一次 AC,给大家分享一下,顺便给点建议 Posted by:hnlwt123 at 2008-08-05 20:10:36
/*思路:假币必然出现在不等式的一端,而且出现的次数必然等于不等式的数量,假币必然符合以下条件:
1.出现在等式中的次数为0
2.出现在不等式的同一端(假设没有一个硬币会同时出现在天平两端)
3.出现次数等于不等式出现的次数
满足以上条件的我们认为它符合规格,如果符合规格的硬币大于1个则与题设矛盾。故可以判断出假币.
*/
#include<stdio.h>
#include<string.h>
typedef struct{
	int left;
	int right;
	int equal;
}Da;//left<right
int main()
{
	int n,k,i,j,x,u,count;
	int Buf[1001];
	char c[2];
	freopen("in.txt","r",stdin);

	memset(N,0,sizeof(N));
	scanf("%d %d",&n,&k);
	for(i=1,u=0;i<=k;i++){
		scanf("%d",&x);
		for(j=1;j<=2*x;j++)
			scanf("%d",&Buf[j]);
		scanf("%s",c);
		if(c[0]=='=')
			for(j=1;j<=2*x;j++)
				N[Buf[j]].equal++;
		else if(c[0]=='>'){
			u++;
			for(j=1;j<=x;j++)
				N[Buf[j]].right++;
			while(j<=2*x)
				N[Buf[j++]].left++;
		}//else if
		else if(c[0]=='<'){
			u++;
			for(j=1;j<=x;j++)
				N[Buf[j]].left++;
			while(j<=2*x)
				N[Buf[j++]].right++;
		}//else if
	}
	count=0;
	if(u)
		for(i=1;i<=n;i++){
			if(N[i].left==u&&!N[i].equal&&!N[i].right){
				count++;
				x=i;
			}
			if(N[i].right==u&&!N[i].equal&&!N[i].left){
				count++;
				x=i;
			}
		}
	else
		for(i=1;i<=n;i++){
			if(!N[i].equal){
				count++;
				x=i;
			}
		}
	if(count==1)
		printf("%d",x);
	else
		printf("0");
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator