| ||||||||||
| 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 | |||||||||
Re:奇怪,穷举怎么都会错?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator