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

Re:奇怪,穷举怎么都会错?

Posted by liewu at 2006-04-21 11:12:24 on Problem 1013
In Reply To:奇怪,穷举怎么都会错? Posted by:yangguo981 at 2005-12-22 16:43:53
我穷举没错啊

#include<iostream>
#include<string>
using namespace std;
bool counterfeit(string a,string b,string c,int j);
bool find(string ptr,int j);
char coins[25] = "AABBCCDDEEFFGGHHIIJJKKLL";
string updown[] ={"up","down"},even = "even";


 int main()
{
	int n;
	cin>>n;
	string s[9];
	for(int i = 0;i < n;i++){
		for(int m = 0;m < 9;m++)
			cin>>s[m];
		for(int j = 0;j < 24;j++){
			if(counterfeit(s[0],s[1],s[2],j) && counterfeit(s[3],s[4],s[5],j) && counterfeit(s[6],s[7],s[8],j)){
				cout<<coins[j]<<" is the counterfeit coin and it is "<<(j % 2 ? "light." : "heavy.")<<endl;
				break;
			}
		}
	}
	return 0;
}

bool counterfeit(string a,string b,string c,int j)
{
		if(find(a,j) && !find(b,j) && (c == updown[j % 2]))
			return true;
		else if((!find(a,j)) && find(b,j) && (c == updown[(j + 1) % 2]))
			return true;
		else if(!find(a,j) && !find(b,j) && (c == even))
			return true;
		else
			return false;
}

bool find(string s,int j){
	for(int i = 0;i < 6;i++){
		if(s[i] == coins[j])
			return true;
	}
	return false;
}

	

		


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