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

枚举的思路

Posted by oyjpart at 2007-02-16 15:03:58 on Problem 1013
#include <stdio.h>
int main() {
	int ntc, i, j, k, d[3], l;
	char a[3][7], b[3][7], tmp[5];
	scanf("%d", &ntc);
	while(ntc--) {
		for(i = 0; i<3; i++) {
			scanf("%s %s %s", a[i], b[i], tmp);
			if(tmp[0] == 'd') d[i] = -1;
			else d[i] = tmp[0] == 'u';
		}
		for(i = 0; i<12; i++) 
			for(l = -1; l<=1; l+= 2) {
				for(j = 0; j<3; j++) {
					int wa = 0, wb = 0;
					for(k = 0; a[j][k]; k++) wa += (a[j][k]-'A'==i)*l;
					for(k = 0; b[j][k]; k++) wb += (b[j][k]-'A'==i)*l;
					if(wa - wb != d[j])		break;
				}
				if(j != 3) continue;
				printf("%c is the counterfeit coin and it is ", (char)(i+'A'));
				if(l == 1) printf("heavy.\n");
				else printf("light.\n");
			}
	}
	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