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 Gensokyo, Ibuki 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

#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
*/
ZOJ 3526 Weekend Party的更多相关文章
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
- zoj 1788 Quad Trees
zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
- ZOJ 1958. Friends
题目链接: ZOJ 1958. Friends 题目简介: (1)题目中的集合由 A-Z 的大写字母组成,例如 "{ABC}" 的字符串表示 A,B,C 组成的集合. (2)用运算 ...
随机推荐
- junit单元测试+junit与Spring结合
配置:右键要加入单元测试的工程,选择properties,然后选择java build path,选择add library,选择junit即可. 编写:右键要测试的class,new一个junit ...
- Oracle 11g 安装环境配置脚本
#!/bin/bash #Test in RHEL 5.5 for 11g c=`cat /etc/shadow | grep oracle | wc -l`if [ $c != 0 ]then w ...
- git应用基础配置
1.注册github账号.注册的时候会要求输入用户名和email这是配置git必须的要素 2.在使用git的时候首先需要把注册时候配合的用户名和密码填在git仓库的配置文件里,如下 harvey@ha ...
- 【Android开发日记】之入门篇(十三)——Android的控件解析
Android的控件都派生自android.view.View类,在android.widget包中定义了大量的系统控件供开发者使用,开发者也可以从View类及其子类中,派生出自定义的控件. 一.An ...
- 使用@CrossOrigin实现跨域请求
1.毕设使用的是react+java开发的网上书城,大家都知道react主要是视图(表现层或页面),数据的处理还是通过java来实现的,所以我的毕设相当于是两个项目组成的,一个是前端项目,一个是后台项 ...
- win32 sdk列表视图控件(ListCtrl或ListView)资料整理
列表视图控件是一种非常常用的控件,在需要以报表形式显示数据时,列表控件通常是最好的选择,许多专用的数据报表控件,也是在它的基础上派生而来.与树视图类似,列表控件可以由多个子项目组成,可以设置为Icon ...
- MATLAB求解常微分方程:ode45函数与dsolve函数
ode45函数无法求出解析解,dsolve可以求出解析解(若有),但是速度较慢. 1. ode45函数 ①求一阶常微分方程的初值问题 [t,y] = ode45(@(t,y)y-2*t/y, ...
- php判断检测一个数组里有没有重复的值
php判断检测一个数组里有没有重复的值 php里有一个处理数组重复值得函数array_unique,我们的思路就是用这个函数来实现的. if (count($array) != count(array ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统
http://www.tuicool.com/articles/NfyqQr 本节主要知识点是easyui 的手风琴加树结构做菜单导航 有园友抱怨原来菜单非常难看,但是基于原有树形无限级别的设计,没有 ...
- HDU 1325 Is It A Tree?(并查集)
题目大意: 给你两个节点,前者指向后者(可以认为前者是后者的父节点),然后让你判断是否是一棵树. 解题思路: 先说说这道题和小希的迷宫(HDU1272)那道题的区别,前者给出的两个点是有方向的,而后者 ...