zoukankan      html  css  js  c++  java
  • ZOJ 3526 Weekend Party

    Weekend Party

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    As the only Oni (a kind of fabulous creature with incredible strength and power) living on the surface of GensokyoIbuki Suika has an interest in gatheringHumans and Youkai in Gensokyo and holding party every day.

    Today Suika has asked several friends to participate in a weekend party, which will be held at Hakurei Shrine as usual. Though Gensokyo was isolated from the outside world, everyone here is still a fan of ACG (Anime, Comic and Game). Of course, some people may only like parts of ACG. For example, Reimulikes Anime and Game, Marisa only likes Comic but Kaguya likes all of them.

    TH_SuikasParty.jpg

    In order to make everyone enjoy the party, Suika decide to arrange them into a circle so that everyone can have at least one common interest with both left and right hand side, which means one has at least a common interest with left AND has at least a common interest with right. By the way, Suika knows all her friends' interest. Please find out if she can get an arrangement of seats that satisfies the constraint described above.

    Input

    There are multiple test cases. For each test case:

    The first line contains an integer N (1 <= N <= 64) indicates the number of girls in Gensokyo. Then followed by N lines, each line contains two strings Ai andBi (each contains only alphanumeric characters). Ai represents the name of the i-th girl and the length of it will not exceed 10. Bi is a non-empty subset of "ACG".

    Output

    For each test case, output "Yes" if there exists at least one arrangement of seats, otherwise output "No".

    Sample Input

    1
    Reimu AG
    2
    Reimu AG
    Marisa C
    3
    Reimu AG
    Marisa C
    Kaguya GAC
    

    Sample Output

    Yes
    No
    No
    

    题意:告诉n个人,每一个人都有AGC这三个爱好中的一种或多种。聚会时间,大家坐成一个圈。为了让大家都欢乐。那么就要保证每一个人左右两边的人都和他有共同爱好。


    思路:仅仅有三个爱好嘛,情况比較少,所以能够直接暴力枚举。先用map缩一下点。方便讨论,然后找一个讨论对象,AGC这样的万能的就无需过多考虑,AG AC GC也还好,可是对于单个爱好的人。就会比較棘手。所以我们选择单个爱好的人作为突破口。感觉代码凝视已经非常具体了。还是不懂滴。能够留言大笑
    #include <iostream>
    #include <stdio.h>
    #include <string>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <map>
    using namespace std;
    
    int n;
    string s,a;
    
    int main()
    {
        while(~scanf("%d",&n))
        {
            map<string,int>mp;
            for(int i=0;i<n;i++)
            {
                cin>>a>>s;mp[s]++;
            }
    
            int A=mp["A"];
            int C=mp["C"];
            int G=mp["G"];
            int AG=mp["AG"]+mp["GA"];
            int AC=mp["AC"]+mp["CA"];
            int GC=mp["GC"]+mp["CG"];
            int AGC=mp["AGC"]+mp["ACG"]+mp["CGA"]+mp["CAG"]+mp["GCA"]+mp["GAC"];
    
            //cout<<"A="<<A<<" "<<"C="<<C<<" "<<"G="<<G<<endl;
    
            //cout<<"AG="<<AG<<" "<<"AC="<<AC<<" "<<"GC="<<GC<<endl;
            //cout<<"AGC="<<AGC<<endl;
    
            if( (A+AC+AG+AGC==n) || (C+AC+AGC+GC==n) || (G+AG+GC+AGC==n) )//一个
             {
                 puts("Yes");
                 //cout<<"********1"<<endl;
                 continue;
             }
            if( (A==0&&(GC+AGC>=2)) || (C==0 && (AG+AGC)>=2 ) || (G==0 && (AC+AGC)>=2 ))//两个
             {
                 puts("Yes");
                 //cout<<"********2"<<endl;
                 continue;
             }
            if( (AG?1:0)+(GC?1:0)+(AC?

    1:0)+AGC>=3 )//三个 { puts("Yes"); //cout<<"********3"<<endl; continue; } if( (AC>=2&&AG>=2) || (AG>=2&&GC>=2) || (GC>=2&&AC>=2) )//三个 { puts("Yes"); //cout<<"********4"<<endl; continue; }

    //对于这样的没有的情况,事实上上面已经包括了。比如:假设仅仅有AC AG GC中的两个(AGC比較特殊,能够无所谓)那么在第一种情况就推断了。能够输出Yes,假设三个都有,那
    //么在第三种情况也会考虑到。所以输出Yes.
    //        if( (A==0&&C==0&&G==0) && ( (AG>=1&&AC>=1) || (AC>=1&&GC>=1) || (GC>=1&&AG>=1) || AGC>=2) )//没有
    //         {
    //             puts("Yes");
    //              //cout<<"********4"<<endl;
    //             continue;
    //         }
    
             puts("No");
        }
        return 0;
    }
    
    /*
    5
    fd A
    fdfd G
    fsd C
    ds AG
    fsf CA
    */
    







  • 相关阅读:
    图解攻略:轻松在苹果Macbook Air上装Win7
    Redis的安装与idea中的使用
    CAD中如何裁剪需要的区域
    Layui 使用问题汇总
    Instant Run 的操作影响到了代码,导致Android App启动闪退的问题
    Android studio百度地图demo出现230错误,key校验失败
    「小程序JAVA实战」小程序注册界面的开发(29)
    「小程序JAVA实战」小程序和后台api通信(28)
    「小程序JAVA实战」小程序多媒体组件(27)
    「小程序JAVA实战」小程序导航组件(26)
  • 原文地址:https://www.cnblogs.com/mfmdaoyou/p/6735521.html
Copyright © 2011-2022 走看看