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

蛮力法,32ms 一次 AC,给大家分享一下,顺便给点建议

Posted by hnlwt123 at 2008-08-05 20:10:36 on Problem 1029
#include<stdio.h>
int t1,t2;       //t1,t2记录假币出现在天平的哪侧。
void change(int *p)         
{
	int i,t,m=p[0];
	for(i=1;i<=m;i++)
	{t=p[i];p[i]=p[m+i];p[m+i]=t;} 
}
int JB(int n,int *p,char c)   //判断i是否与称量记录矛盾。
{
	int i,m,f;
	m=p[0];
	for(i=f=1;i<=m&&f;i++)
	{
		if(p[i]==n) {f=0;t1=1;}
		if(p[m+i]==n){f=0;t2=1;}
	}
	if(!f&&c=='='||f&&c!='=')
		return 0;
	return 1;
}
void main()
{
	int i,j,k,M,N,K,no,num[100][2001];
	char c[100];
	FILE *fp=fopen("gold.in","r");
	fscanf(fp,"%d",&M);
	for(i=0;i<M;i++)
	{
		int t=0;
		fscanf(fp,"%d%d",&N,&K);
		for(j=0;j<K;j++)
		{
			fscanf(fp,"%d",&num[j][0]);
			for(k=1;k<=2*num[j][0];k++)
				fscanf(fp,"%d",&num[j][k]);
			fscanf(fp,"\n%c",&c[j]);
		}
		for(j=0;j<K;j++)         //'>'的情况把天平两端的金币交换;
		{
			if(c[j]=='>')
			{
				change(num[j]);
				c[j]='<';
			}
		}
		for(j=1;j<=N;j++)
		{   t1=t2=0;
			for(k=0;k<K&&JB(j,num[k],c[k]);k++);
			if(k<K) continue;
			if(t1==t2&&t1==1)continue;
			no=j;t++;
		}
		if(t==1) printf("%d\n",no);
		else printf("0\n");
	}
}

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