| ||||||||||
| 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 | |||||||||
修正+附个码。。In Reply To:小计数法 Posted by:lilingfei at 2015-04-22 22:36:08 > 1、遇到even的则都标记为真钱
> 2、遇到up的把两边swap
> 3、遇到up/down则把每个可疑钱币在两边出现的次数+1
> 4、三次完毕后,假钱一定在某一边出现了与up/down相同的次数。在左边就轻,右边就重。
第3步表达有误。。应该将可疑钱币在出现的那边的计数器+1
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
int main(){
int kase;
cin>>kase;
while(kase--) {
int ok[30], cnt1[30], cnt2[30], down = 0, n;
memset(ok, 0, sizeof(ok));
memset(cnt1, 0, sizeof(cnt1));
memset(cnt2, 0, sizeof(cnt2));
string s1, s2, s3;
for(int i = 0; i < 3; i ++) {
cin>>s1>>s2>>s3;
n = s1.length();
if(s3 == "even") {
for(int j = 0; j < n; j ++) {
ok[s1[j]-'A'] = 1;
ok[s2[j]-'A'] = 1;
}
}
else {
if(s3 == "up") swap(s1, s2);
for(int j = 0; j < n; j ++) {
int a = s1[j]-'A', b = s2[j]-'A';
if(!ok[a]) cnt1[a] ++;
if(!ok[b]) cnt2[b] ++;
}
down ++;
}
}
for(int i = 0; i < 30; i ++) {
if(!ok[i]){
if(cnt1[i] == down) printf("%c is the counterfeit coin and it is light.\n", i + 'A');
else if(cnt2[i] == down) printf("%c is the counterfeit coin and it is heavy.\n", i+'A');
}
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator