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.

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
*/

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-31 21:16:23

ZOJ 3526 Weekend Party的相关文章

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 最小生成树 Kruskal算法

题目链接:ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 Building a Space Station Time Limit: 2 Seconds      Memory Limit: 65536 KB You are a member of the space station engineering team, and are assigned a task in the construction process of the statio

ZOJ 3607 Lazier Salesgirl (贪心)

Lazier Salesgirl Time Limit: 2 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy

ZOJ - 2243 - Binary Search Heap Construction

先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal n

ZOJ 2859 二维线段树

思路:自己写的第二发二维线段树1A,哈哈,看来对二维的push操作比较了解了:但是还没遇到在两个线段树中同时进行push操作的,其实这题我是想在x维和y维同时进行push操作的,但是想了好久不会,然后看到这题又给出10秒,然后想想在x维线段直接单点查询肯定也过了,然后在第二维就只有pushup操作,在第一维线段树没有pushup操作.要是在第一维也有pushup操作的话,那就不用单点查询那么慢了.不过也A了,想找题即在二维同时进行pushup和pushdown操作的. #include<iost

ZOJ 2588

求一个无向图的桥(可能存在重边),输出割边的数目,并按顺序输出割边的序号(输入的顺序). 由于内存的限制 , 无法使用邻接矩阵 , 只能用邻接表了 . 第一次用了邻接表,超内存了: 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <string.h> 5 using namespace std; 6 const int N=10002; 7 const i

ZOJ 2587 Unique Attack 判断最小割是否唯一

很裸的判断最小割是否唯一.判断方法是先做一遍最大流求最小割,然后从源点和汇点分别遍历所有能够到达的点,看是否覆盖了所有的点,如果覆盖了所有的点,那就是唯一的,否则就是不唯一的. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostr

ZOJ 3794 Greedy Driver spfa

题意: 给定n个点,m条有向边,邮箱容量. 起点在1,终点在n,开始邮箱满油. 下面m行表示起点终点和这条边的耗油量(就是长度) 再下面给出一个数字m表示有P个加油站,可以免费加满油. 下面一行P个数字表示加油站的点标. 再下面一个整数Q 下面Q行 u v 表示在u点有销售站,可以卖掉邮箱里的任意数量的油,每以单位v元. 问跑到终点能获得最多多少元. 先求个每个点的最大剩余油量 f[i], 再把边反向,求每个点距离终点的最短路 dis[i]. 然后枚举一下每个销售点即可,( f[i] - dis