| ||||||||||
| 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:SeedJYH at 2006-04-02 22:27:56 汗.....
先把所有的置为0,依次遍历下,从A->K依次按重的先搜一遍,如果有伪假币(不一定是假的)的先置为1,(第二次搜重的时候置为-1) up为1,even为0 ,down 为-1,看表达式是不是成立
看下我的代码,有很多不必要得(其实重的和轻的一样)
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
int a[10]={0},i,j;
string statu[9];
for(i=0;i<9;i++)
{
cin>>statu[i];
if((i+1)%3==0)
{
if(statu[i]=="up") a[i]=1;
else if(statu[i]=="even") a[i]=0;
else a[i]=-1;
}
}
int true_false=-1;
//先处理假币是重的情况
for(i=0;i<13;i++)
{
for(j=0;j<9;j++)
{
if((j+1)%3!=0 && statu[j].find(i+65)!=-1)
a[j]=1;
}
if(a[0]-a[1]==a[2] && a[3]-a[4]==a[5] && a[6]-a[7]==a[8])
{
true_false=i;break; //得到假币,退出
}
else
{
for(j=0;j<9;j++)
{
if((j+1)%3!=0) //否则还原原来的值
a[j]=0;
}
}
}
if(true_false!=-1) cout<<char(i+65)<<" is the counterfeit coin and it is heavy."<<endl;
else //处理假币是轻的情况
{
for(i=0;i<13;i++)
{
for(j=0;j<9;j++)
{
if((j+1)%3!=0 && statu[j].find(i+65)!=-1)
a[j]=-1;
}
if(a[0]-a[1]==a[2] && a[3]-a[4]==a[5] && a[6]-a[7]==a[8])
{
true_false=i;break; //得到假币,退出
}
else
{
for(j=0;j<9;j++)
{
if((j+1)%3!=0) //否则还原原来的值
a[j]=0;
}
}
}
cout<<char(i+65)<<" is the counterfeit coin and it is light."<<endl;
}
}
return 0;
}
自己都懒得改了....
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator