Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不知道为什么会WA,各种测试样例都过了,求大神看看。。

Posted by yangyang_1994 at 2015-06-08 22:48:54 on Problem 1013
#include<iostream>
#include<string>
#include<cstdio>
#include<map>
using namespace std;

string a[4],b[4],c[4];

const int inf = 0xfffffff;
int maybe[13];
string res1;

int judge(char str) //猜测str为假币
{
    int i;
    int j;
    bool flag = 0,flag1 = 0,flag2 = 0,flag3 = 0;
    int cnt = 0,cnt1 = 0;
    for(i=0; i<3; i++)
    {
        for(j=0; j<a[i].length(); j++)
        {
            if(str == a[i][j] && c[i] == "up")  //假币在左,左重
            {
                flag = 1;
                res1 = "heavy";
            }
            else if(str == a[i][j] && c[i] == "down") //假币在左,左轻
            {
                flag1 = 1;
                res1 = "light";
            }
            else if(str == b[i][j] && c[i] == "up") //假币在右,右轻
            {
                flag2 = 1;
                res1 = "light";
            }
            else if(str == b[i][j] && c[i] == "down") //假币在右,右重
            {
                flag3 = 1;
                res1 = "heavy";
            }
        }
    }
    if(flag == 1) ////假币在左,左重
    {
        if(flag1 != 1 && flag2 != 1)
        {
            return true;
        }
    }
    else if(flag1 == 1) //假币在左,左轻
    {
        if(flag != 1 && flag3 != 1)
        {
            return true;
        }
    }
    else if(flag2 == 1) //假币在右,右轻
    {
        if(flag3 != 1 && flag != 1)
        {
            //cout<<"flag"<<endl;
            return true;
        }
    }
    else if(flag3 == 1) //假币在右,右重
    {
        if(flag2 != 1 && flag1 != 1)
        {
            return true;
        }
    }
    else
    {
        return false;
    }
}

int main()
{
    int m;
    //freopen("111","r",stdin);
    cin>>m;
    map<char,bool> value_key;
    int i,j;
    int max;
    while(m--)
    {
        char res;
        max = -inf;
        for(i=0; i<12; i++)
        {
            char sign = i + 'A';
            value_key[sign] = false;
            maybe[i] = 0;
        }
        for(i=0; i<3; i++)
        {
            cin>>a[i]>>b[i]>>c[i];
        }
        for(i=0; i<3; i++)
        {
            if(c[i] == "even")
            {
                for(j=0; j<a[i].length(); j++)
                {
                    value_key[a[i][j]] = true;
                }
                for(j=0; j<b[i].length(); j++)
                {
                    value_key[b[i][j]] = true;
                }
            }
        }
        /*
        如果天平不平衡且没有出现在天平上的为真币
        */
        int alpha[13],j;
        for(i=0; i<12; i++)
        {
            alpha[i] = 0;
        }
        for(i=0; i<3; i++)
        {
            if(c[i] == "down" || c[i] == "up")
            {
                for(j=0; j<a[i].length(); j++)
                {
                    char str3 = a[i][j];
                    int temp = str3 - 'A';
                    alpha[temp]++;
                }
                for(j=0; j<b[i].length(); j++)
                {
                    char str3 = b[i][j];
                    int temp = str3 - 'A';
                    alpha[temp]++;
                }
                for(j=0; j<12; j++)
                {
                    if(alpha[j] == 0) //表示没有出现过
                    {
                        //cout<<j<<endl;
                        value_key[j+'A'] = true;
                    }
                    alpha[j] = 0;
                }
            }
        }


        for(i=0; i<12; i++)
        {
            char sign = i + 'A';
            if(value_key[sign] == false) //枚举开始
            {
                if(judge(sign))
                {
                    res = sign;
                    break;
                }
            }
        }
        cout<<res<<" is the counterfeit coin and it is "<<res1<<"."<<endl;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator