zoukankan      html  css  js  c++  java
  • 模拟,找次品硬币,Counterfeit Dollar(POJ 1013)

    题目链接:http://poj.org/problem?id=1013

    解题报告:

    1、由于次品的重量不清楚,用time['L'+1]来记录各个字母被怀疑的次数。为负数则轻,为正数则重。

    2、用zero['L'+1]记录当天平结果是even时,硬币绝对是真,true;

    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            char left[3][6],right[3][6],result[3][6];
    
            int time['L'+1]= {0}; ///标记各个字母被怀疑的次数;
            bool zero['L'+1]= {false}; ///标记字母绝对是真币;
    
            for(int k=0; k<3; k++)
                cin>>left[k]>>right[k]>>result[k];
    
            for(int i=0; i<3; i++) ///3次判断
            {
                ///检查天平状态
                switch(result[i][0])
                {
                case 'e':///天平平衡
                {
                    for(int j=0; left[i][j]!=''; j++)
                    {
                        zero[left[i][j]]=true;
    
                        zero[right[i][j]]=true;
                    }
                    break;
                }
                case 'u':///天平右边轻些
                {
                    for(int j=0; left[i][j]!=''; j++)
                    {
                        time[left[i][j]]++;
    
                        time[right[i][j]]--;
                    }
                    break;
                }
                case 'd':///天平右边重些
                {
                    for(int j=0; left[i][j]!=''; j++)
                    {
                        time[left[i][j]]--;
    
                        time[right[i][j]]++;
                    }
                    break;
                }
                }
            }
    
    
            int Max=-1;///查找被怀疑程度最高的硬币
            char alpha;
            for(int j='A';j<='L';j++)
            {
                if(zero[j])
                    continue;
    
                if(Max<=abs(time[j]))
                {
                    Max=abs(time[j]);
                    alpha=j;
                }
            }
            cout<<alpha<<" is the counterfeit coin and it is ";
            if(time[alpha]>0)
                cout<<"heavy.
    ";
            else cout<<"light.
    ";
        }
        return 0;
    }
  • 相关阅读:
    Teradata中fastload使用
    Teradata 的rank() 和 row_number() 函数
    Oracle 10g下载链接
    SSH时不需输入密码
    Linux环境下GIT初次使用
    模块与包的概念
    迭代器 生成器
    Python
    Python
    函数式编程-尾递归、尾调用
  • 原文地址:https://www.cnblogs.com/TreeDream/p/5299714.html
Copyright © 2011-2022 走看看