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. 1
  2. Reimu AG
  3. 2
  4. Reimu AG
  5. Marisa C
  6. 3
  7. Reimu AG
  8. Marisa C
  9. Kaguya GAC

Sample Output

  1. Yes
  2. No
  3. No

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


思路:仅仅有三个爱好嘛,情况比較少,所以能够直接暴力枚举。先用map缩一下点。方便讨论,然后找一个讨论对象,AGC这样的万能的就无需过多考虑,AG AC GC也还好,可是对于单个爱好的人。就会比較棘手。所以我们选择单个爱好的人作为突破口。感觉代码凝视已经非常具体了。还是不懂滴。能够留言
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string>
  4. #include <cstring>
  5. #include <cmath>
  6. #include <algorithm>
  7. #include <map>
  8. using namespace std;
  9.  
  10. int n;
  11. string s,a;
  12.  
  13. int main()
  14. {
  15. while(~scanf("%d",&n))
  16. {
  17. map<string,int>mp;
  18. for(int i=0;i<n;i++)
  19. {
  20. cin>>a>>s;mp[s]++;
  21. }
  22.  
  23. int A=mp["A"];
  24. int C=mp["C"];
  25. int G=mp["G"];
  26. int AG=mp["AG"]+mp["GA"];
  27. int AC=mp["AC"]+mp["CA"];
  28. int GC=mp["GC"]+mp["CG"];
  29. int AGC=mp["AGC"]+mp["ACG"]+mp["CGA"]+mp["CAG"]+mp["GCA"]+mp["GAC"];
  30.  
  31. //cout<<"A="<<A<<" "<<"C="<<C<<" "<<"G="<<G<<endl;
  32.  
  33. //cout<<"AG="<<AG<<" "<<"AC="<<AC<<" "<<"GC="<<GC<<endl;
  34. //cout<<"AGC="<<AGC<<endl;
  35.  
  36. if( (A+AC+AG+AGC==n) || (C+AC+AGC+GC==n) || (G+AG+GC+AGC==n) )//一个
  37. {
  38. puts("Yes");
  39. //cout<<"********1"<<endl;
  40. continue;
  41. }
  42. if( (A==0&&(GC+AGC>=2)) || (C==0 && (AG+AGC)>=2 ) || (G==0 && (AC+AGC)>=2 ))//两个
  43. {
  44. puts("Yes");
  45. //cout<<"********2"<<endl;
  46. continue;
  47. }
  48. if( (AG?1:0)+(GC?1:0)+(AC?
  49.  
  50. 1:0)+AGC>=3 )//三个
  51. {
  52. puts("Yes");
  53. //cout<<"********3"<<endl;
  54. continue;
  55. }
  56.  
  57. if( (AC>=2&&AG>=2) || (AG>=2&&GC>=2) || (GC>=2&&AC>=2) )//三个
  58. {
  59. puts("Yes");
  60. //cout<<"********4"<<endl;
  61. continue;
  62. }
  1.  
  1. //对于这样的没有的情况,事实上上面已经包括了。比如:假设仅仅有AC AG GC中的两个(AGC比較特殊,能够无所谓)那么在第一种情况就推断了。能够输出Yes,假设三个都有,那
  1. //么在第三种情况也会考虑到。所以输出Yes.
  2. // if( (A==0&&C==0&&G==0) && ( (AG>=1&&AC>=1) || (AC>=1&&GC>=1) || (GC>=1&&AG>=1) || AGC>=2) )//没有
  3. // {
  4. // puts("Yes");
  5. // //cout<<"********4"<<endl;
  6. // continue;
  7. // }
  8.  
  9. puts("No");
  10. }
  11. return 0;
  12. }
  13.  
  14. /*
  15. 5
  16. fd A
  17. fdfd G
  18. fsd C
  19. ds AG
  20. fsf CA
  21. */

ZOJ 3526 Weekend Party的更多相关文章

  1. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  2. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  3. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  4. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  5. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  6. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  7. ZOJ Problem Set - 1001 A + B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...

  8. zoj 1788 Quad Trees

    zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...

  9. ZOJ 1958. Friends

    题目链接: ZOJ 1958. Friends 题目简介: (1)题目中的集合由 A-Z 的大写字母组成,例如 "{ABC}" 的字符串表示 A,B,C 组成的集合. (2)用运算 ...

随机推荐

  1. ORACLE导入、导出所有数据到文件的SQL语句

    打开cmd窗口,执行如下SQL语句即可 --导出 exp 用户名/密码@localhost/orcl file=d:\111.dump log=d:111.log --或者 1.登录管理员system ...

  2. Java==与equals方法的区别

    摘自:http://www.cnblogs.com/dolphin0520/p/3592500.html 1.对于==,如果作用于基本数据类型的变量,则直接比较其存储的 “值”是否相等: 如果作用于引 ...

  3. python基础复习-1-1文件类型、变量、运算符、表达式

    文件类型: .py python源文件 由python解释器执行 .pyc python源码编译后生成的文件(字节代码) 编译方法: 源码文件中使用py_compile模块 import py_com ...

  4. git常用命令收集

    [git远程操作命令] 1.$ git remote –v #查看本地配置的所有远程仓库,内容为远程仓库的地址和本地别名 harvey@harvey:~/node$ git remote -v nod ...

  5. Python 进阶 之 yield

    .转载自:https://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/ Python yield 使用浅析: 您可能听说过, ...

  6. C指针详解

    前言:复杂类型说明 要了解指针,多多少少会出现一些比较复杂的类型,所以我先介绍一下如何完全理解一个复杂类型,要理解复杂类型其实很简单,一个类型里会出现很多运算符,他们也像普通的表达式一样,有优先级,其 ...

  7. HDU 6354.Everything Has Changed-简单的计算几何、相交相切圆弧的周长 (2018 Multi-University Training Contest 5 1005)

    6354.Everything Has Changed 就是计算圆弧的周长,总周长=大圆周长+相交(相切)部分的小圆的弧长-覆盖掉的大圆的弧长. 相交部分小圆的弧长直接求出来对应的角就可以,余弦公式, ...

  8. (3)webApi postman使用

    https://www.getpostman.com/

  9. 让你的mysql或mariadb 支持ipv6

    如果你在windows 或Linux系统已经安装了mysql/mariadb,并且操作系统本身已经支持了ipv6. 在/etc/my.conf 这样配置可以让mysql也支持ipv6 [mysqld] ...

  10. Jekins持续集成,gitlab代码仓库

    http://blog.csdn.net/john_cdy/article/details/7738393