D - Counterfeit Dollar(第二季水)
Description
Input
Output
Sample Input
1
ABCD EFGH even
ABCI EFJK up
ABIJ EFGH even
Sample Output
K is the counterfeit coin and it is light. 这道题如果找不到方法那么分好多种情况一种一种来分析很麻烦
开始写的代码就没有找到方法,将题目样例中的情况分析完结果还有好多种情况 以下代码只考虑了样例情况 分析第二种情况时 发现太麻烦了 就停下来了
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int t;
char f1(char* a,char* b,char* c,char* d,char* e,char* f) //a、b、c、d四个even,e、f为up||down
{
int n1=strlen(e),n2=strlen(f);
for(int i=;i<n1;i++){
if(strchr(a,e[i])==NULL&&strchr(b,e[i])==NULL&&strchr(c,e[i])==NULL&&strchr(d,e[i])==NULL){
t=;
return e[i];
}
}
for(int i=;i<n2;i++){
if(strchr(a,f[i])==NULL&&strchr(b,f[i])==NULL&&strchr(c,f[i])==NULL&&strchr(d,f[i])==NULL){
t=;
return f[i];
}
}
}
/*char f2(char* a,char* b,char* c,char* d,char* e,char* f) //a、b为even,其他为up||down
{ }*/
int main()
{
int n,i;
cin>>n; while(n--)
{
char str[][];
char k;
for(i=;i<;i++)cin>>str[i];
for(;i<;i++)cin>>str[i];
for(;i<;i++)cin>>str[i];
//for(i=0;i<9;i++)cout<<i<<" "<<str[i]<<endl;
if(str[][]=='e'&&str[][]=='e'&&(str[][]=='u'||str[][]=='d')){
k=f1(str[],str[],str[],str[],str[],str[]);
cout<<k<<" is the counterfeit coin and it is ";
if(str[][]=='u'){
if(t==)cout<<"heavy. ";
else cout<<"light. ";
}
else{
if(t==)cout<<"light. ";
else cout<<"heavy. ";
}
}
else if(str[][]='e'&&str[][]=='e'&&(str[][]=='u'||str[][]=='d')){
k=f1(str[],str[],str[],str[],str[],str[]);
cout<<k<<" is the counterfeit coin and it is ";
if(str[][]=='u'){
if(t==)cout<<"heavy. ";
else cout<<"light. ";
}
else{
if(t==)cout<<"light. ";
else cout<<"heavy. ";
}
}
else if(str[][]=='e'&&str[][]=='e'&&(str[][]=='u'||str[][]=='d')){
k=f1(str[],str[],str[],str[],str[],str[]);
cout<<k<<" is the counterfeit coin and it is ";
if(str[][]=='u'){
if(t==)cout<<"heavy. ";
else cout<<"light. ";
}
else{
if(t==)cout<<"light. ";
else cout<<"heavy. ";
}
}
/* else if(str[2][0]=='e'&&str[5][0]!='e'&&str[8][0]!='e'){
}
else if(str[5][0]=='e'&&str[2][0]!='e'&&str[8][0]!='e'){
}
else if(str[8][0]=='e'&&str[5][0]!='e'&&str[2][0]!='e'){
}
*/
}
//system("pause");
return ;
}
找找方法 换一种简单的方法来做
给所有银币赋值1
从A开始给银币赋值0或 2 天平两端相加判断是否符合even up down的条件 若符合 则得出结果
#include<iostream>
#include<string>
using namespace std;
int s[];
int f(string a,string b,int n)
{
int p=,q=;
for(int j=;j<n;j++){
p+=s[a[j]-'A'];
q+=s[b[j]-'A'];
}
if(p==q)return ;
if(p>q)return ;
else return -;
}
int main()
{
int n,i;
cin>>n;
while(n--)
{
for(i=;i<;i++)s[i]=;
string str[];
int k;
bool flag=false;
for(i=;i<;i++)cin>>str[i];
for(;i<;i++)cin>>str[i];
for(;i<;i++)cin>>str[i];
int n1=str[].length(),n2=str[].length(),n3=str[].length();
for(i=;i<;i++){
s[i]=;
k=f(str[],str[],n1);
if(!((k==&&str[][]=='e')||(k==&&str[][]=='u')||(k==-&&str[][]=='d'))){
s[i]=;
continue;
}
k=f(str[],str[],n2);
if(!((k==&&str[][]=='e')||(k==&&str[][]=='u')||(k==-&&str[][]=='d'))){
s[i]=;
continue;
}
k=f(str[],str[],n3);
if((k==&&str[][]=='e')||(k==&&str[][]=='u')||(k==-&&str[][]=='d')){
flag=true;
cout<<(char)(i+'A')<<" is the counterfeit coin and it is light. "<<endl;
}
s[i]=;
}
if(!flag){
for(i=;i<;i++){
s[i]=;
k=f(str[],str[],n1);
if(!((k==&&str[][]=='e')||(k==&&str[][]=='u')||(k==-&&str[][]=='d'))){
s[i]=;
continue;
}
k=f(str[],str[],n2);
if(!((k==&&str[][]=='e')||(k==&&str[][]=='u')||(k==-&&str[][]=='d'))){
s[i]=;
continue;
}
k=f(str[],str[],n3);
if((k==&&str[][]=='e')||(k==&&str[][]=='u')||(k==-&&str[][]=='d')){
cout<<(char)(i+'A')<<" is the counterfeit coin and it is heavy. "<<endl;
}
s[i]=;
}
}
}
//system("pause");
return ;
}
D - Counterfeit Dollar(第二季水)的更多相关文章
- F - The Fun Number System(第二季水)
Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight o ...
- S - 骨牌铺方格(第二季水)
Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...
- R - 一只小蜜蜂...(第二季水)
Description 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. ...
- I - Long Distance Racing(第二季水)
Description Bessie is training for her next race by running on a path that includes hills so that sh ...
- Y - Design T-Shirt(第二季水)
Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...
- N - Robot Motion(第二季水)
Description A robot has been programmed to follow the instructions in its path. Instructions for the ...
- B - Maya Calendar(第二季水)
Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old ...
- T - 阿牛的EOF牛肉串(第二季水)
Description 今年的ACM暑期集训队一共有18人,分为6支队伍.其中有一个叫做EOF的队伍,由04级的阿牛.XC以及05级的COY组成.在共同的集训生活中,大家建立了深厚的 ...
- E - Number Sequence(第二季水)
Description A single positive integer i is given. Write a program to find the digit located in the p ...
随机推荐
- c_str()函数
#include <string.h> const char *c_str(); 返回字符串地址,是一个c函数,返回类型const char*c_str()函数返回一个指向正规C字符串的指 ...
- 13年山东省赛 Mountain Subsequences(dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Mountain Subsequences Time Limit: 1 Sec ...
- (原)Matlab的svmtrain和svmclassify
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5554551.html 参考网址: http://www.cnblogs.com/zhangchaoya ...
- VLC的相关文档以及javascript接口
参看下面链接:VLC相关文档
- activiti笔记二:用户任务
1, assignee 代替humanPerformer 功能 2, cadidateUsers代替potentialOwner功能 3, candidateGroups代替potentialOwn ...
- rub、sass和compass的安装
长话短说,直接进入正题. [ruby安装] ruby下载网址:http://rubyinstaller.org/downloads/ 选择适合自己电脑的版本: 下载完成后直接双击安装,记得勾选加入环境 ...
- 2015年阿里巴巴蚂蚁金服校招JAVA研发工程师内推电话面试
没想到阿里校招如此之早,虽然早已进入复习备战状态,但还是感觉有些措手不及...找了个在蚂蚁金服做HR的同学帮忙了内推,然后在最近的几天匆匆忙忙地复习JAVA(之前都把精力放在了数据结构.算法等基础上了 ...
- 数据挖掘(data mining),机器学习(machine learning),和人工智能(AI)的区别是什么? 数据科学(data science)和商业分析(business analytics)之间有什么关系?
本来我以为不需要解释这个问题的,到底数据挖掘(data mining),机器学习(machine learning),和人工智能(AI)有什么区别,但是前几天因为有个学弟问我,我想了想发现我竟然也回答 ...
- C#基础之------进制转换
/************************ File:控制台进制类型转换实现 Time:2014年8月12日 Author:小X ****************************/ 代 ...
- org.springframework.dao.EmptyResultDataAccessException
public Wcrash getWcrashInfo(int id) { String sql = "select plateform_id,android_version,app_ver ...