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

直接模拟 一次稳A 0ms

Posted by zxc97 at 2018-03-30 02:39:29 on Problem 1013
代码比较长,懒得改了
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int Coins[12]={1};
        bool Coins_b[12]={false};
        string str[9];
        for(int j=0;j<9;j++)
        {
            cin>>str[j];
        }
        for(int j=2;j<9;j=j+3) {
            if (str[j] == "even") {
                int k = 0;
                while (str[j - 2][k]) {
                    Coins_b[str[j - 2][k] - 'A'] = true;
                    k++;
                }
                k = 0;
                while (str[j - 1][k]) {
                    Coins_b[str[j - 1][k] - 'A'] = true;
                    k++;
                }
            }
        }
        bool HL=false;
        //假设假币是轻的
        for(int l=0;l<12;l++)
        {
            if(Coins_b[l]) continue;
            memset(Coins,0, sizeof(Coins));
            Coins[l]=-1;
            int count=0;
            for(int j=2;j<9;j=j+3) {
                if (str[j] == "up") {
                    int L=0,R=0;
                    int k = 0;
                    while (str[j - 2][k]) {
                        L+=Coins[str[j-2][k]-'A'];
                        k++;
                    }
                    k = 0;
                    while (str[j - 1][k]) {
                        R+=Coins[str[j-1][k]-'A'];
                        k++;
                    }
                    if(L>R) count++;
                }
                if (str[j] == "even") {
                    int L=0,R=0;
                    int k = 0;
                    while (str[j - 2][k]) {
                        L+=Coins[str[j-2][k]-'A'];
                        k++;
                    }
                    k = 0;
                    while (str[j - 1][k]) {
                        R+=Coins[str[j-1][k]-'A'];
                        k++;
                    }
                    if(L==R) count++;
                }
                if (str[j] == "down") {
                    int L=0,R=0;
                    int k = 0;
                    while (str[j - 2][k]) {
                        L+=Coins[str[j-2][k]-'A'];
                        k++;
                    }
                    k = 0;
                    while (str[j - 1][k]) {
                        R+=Coins[str[j-1][k]-'A'];
                        k++;
                    }
                    if(L<R) count++;
                }
            }
            if(count==3) {
                cout << char(l + 'A') <<" is the counterfeit coin and it is light."<<endl;
                HL=true;
            }
            count=0;
            }
        //假设假币是重的
        if(!HL)
        {
            for(int l=0;l<12;l++)
            {
                if(Coins_b[l]) continue;
                memset(Coins,0, sizeof(Coins));
                Coins[l]=-1;
                int count=0;
                for(int j=2;j<9;j=j+3) {
                    if (str[j] == "up") {
                        int L=0,R=0;
                        int k = 0;
                        while (str[j - 2][k]) {
                            L+=Coins[str[j-2][k]-'A'];
                            k++;
                        }
                        k = 0;
                        while (str[j - 1][k]) {
                            R+=Coins[str[j-1][k]-'A'];
                            k++;
                        }
                        if(L<R) count++;
                    }
                    if (str[j] == "even") {
                        int L=0,R=0;
                        int k = 0;
                        while (str[j - 2][k]) {
                            L+=Coins[str[j-2][k]-'A'];
                            k++;
                        }
                        k = 0;
                        while (str[j - 1][k]) {
                            R+=Coins[str[j-1][k]-'A'];
                            k++;
                        }
                        if(L==R) count++;
                    }
                    if (str[j] == "down") {
                        int L=0,R=0;
                        int k = 0;
                        while (str[j - 2][k]) {
                            L+=Coins[str[j-2][k]-'A'];
                            k++;
                        }
                        k = 0;
                        while (str[j - 1][k]) {
                            R+=Coins[str[j-1][k]-'A'];
                            k++;
                        }
                        if(L>R) count++;
                    }
                }
                if(count==3) {
                    cout << char(l + 'A') <<" is the counterfeit coin and it is heavy."<<endl;
                }
                count=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