zoukankan      html  css  js  c++  java
  • poj模拟1013

    模拟,定义两个数组,visited[],用于记录改点时候为真和w[],用于记录该店被怀疑的次数,或是出现在不相等中的次数;每当出现up或down时,对相比较的两个数组中的点对应的w[]相应的++或是--;因为一定有解,所以假币的w[]的绝对值一定最大;

    #include<iostream>
    using namespace std;
    int main()
    {
        char ch[6][12];
        char judge[6];
        int visited[100];
        int w[100];
        int n;
        cin>>n;
        int i,j;
        int flag=0;
        int f;
        while(n--)
        {
            memset(w,0,sizeof(w));
            memset(visited,0,sizeof(visited));
            for(i=0;i<6;i+=2)
            {
                cin>>ch[i]>>ch[i+1];
                cin>>judge;
                if(strcmp(judge,"even")==0)
                {
                    for(j=0;j<strlen(ch[i]);j++)
                    {
                        visited[(int)ch[i][j]]=1;
                        visited[(int)ch[i+1][j]]=1;
                    }
                }
                else
                {
                    int k;
                    flag=i;
                    if(strcmp(judge,"up")==0)
                        f=1;
                    else
                        f=2;
                    if(strcmp(judge,"up")==0)
                    {
                        for(k=0;k<strlen(ch[i]);k++)
                        {
                            w[(int)ch[i][k]]++;
                            w[(int)ch[i+1][k]]--;
                        }
                    }
                    else
                    {
                        for(k=0;k<strlen(ch[i]);k++)
                        {
                            w[(int)ch[i][k]]--;
                            w[(int)ch[i+1][k]]++;
                        }
                    }
            
                    for(j=65;j<65+12;j++)
                    {
                        for(k=0;k<strlen(ch[i]);k++)
                        {
                            if((char)j==ch[i][k]||(char)j==ch[i+1][k])
                                break;
                        }
                        if(k>=strlen(ch[i]))
                            visited[j]=1;
                    }
                }
            }
            int max=-1;
            int r=0;
            for(j=65;j<65+12;j++)
            {
                //cout<<visited[j]<<" "<<w[j]<<endl;
                if(!visited[j]&&max<abs(w[j]))
                {
                    max=abs(w[j]);
                    r=j;    
                }
            }
            cout<<(char)r;
            cout<<" is the counterfeit coin and it is ";
                    
                    
                    
                            if(w[r]>0)
                                cout<<"heavy."<<endl;
                                else
                                cout<<"light."<<endl;
                           
                
                
    
        }
        return 0;
    }
  • 相关阅读:
    Metroid Prime (Wii) Chs 20100120
    刀削面
    胶水帝
    一种新思维,一个新起点
    MP+
    涂鸦
    Metroid Prime (Wii) Chs 20100117
    Cypress 68013 and UMDF
    Metroid Prime Chs 20091010
    process VS thread
  • 原文地址:https://www.cnblogs.com/orangeblog/p/2453898.html
Copyright © 2011-2022 走看看