zoj 3601 Unrequited Love(STL,灵活题)
来源:互联网 发布:手机淘宝评价管理 编辑:程序博客网 时间:2024/05/24 03:13
There are n single boys and m single girls. Each of them may love none, one or several of other people unrequitedly and one-sidedly. For the coming q days, each night some of them will come together to hold a single party. In the party, if someone loves all the others, but is not loved by anyone, then he/she is called king/queen of unrequited love.
Input
There are multiple test cases. The first line of the input is an integer T ≈ 50 indicating the number of test cases.
Each test case starts with three positive integers no more than 30000
-- n m q
. Then each of the next n lines describes a boy, and each of the next m lines describes a girl. Each line consists of the name, the number of unrequitedly loved people, and the list of these people's names. Each of the last q lines describes a single party. It consists of the number of people who attend this party and their names. All people have different names whose lengths are no more than 20
. But there are no restrictions that all of them are heterosexuals.
Output
For each query, print the number of kings/queens of unrequited love, followed by their names in lexicographical order, separated by a space. Print an empty line after each test case. See sample for more details.
Sample Input
22 1 4BoyA 1 GirlCBoyB 1 GirlCGirlC 1 BoyA2 BoyA BoyB2 BoyA GirlC2 BoyB GirlC3 BoyA BoyB GirlC2 2 2H 2 O SHe 0O 1 HS 1 H3 H O S4 H He O S
Sample Output
001 BoyB000
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4704
#include<iostream>#include<algorithm>#include<string>#include<map>#include<set>#include<cmath>#include<string.h>#include<stdlib.h>#include<cstdio>#define ll long longusing namespace std;int main(){int t;cin>>t;while(t--){set<string> x[30001]; //set的 .count用法,学习 map<string,int> id; //把每个人转换成数字下标i,对应x[i]string z[30001];string h,w;int n,m,a,b;cin>>n>>m>>a;int p=-1;for(int i=0;i<n+m;++i){cin>>h>>b;if(id.count(h)==0)id[h]=++p;for(int j=0;j<b;++j){cin>>w;x[id[h]].insert(w);}}for(int i=0;i<a;++i){cin>>b;for(int j=0;j<b;++j)cin>>z[j];string g=z[0];int flag=0;for(int j=1;j<b;++j){if(!x[id[z[flag]]].count(z[j])||x[id[z[j]]].count(z[flag])){//如果没有进入这个if,那就说明z[flag]肯定满足,反过来即z[j]肯定不满足 g=z[j]; flag=j;}} //如果z[flag]不满足了,那就把flag换成j,再继续看z[flag']满不满足 for(int j=0;j<flag;++j){if(!x[id[z[flag]]].count(z[j])||x[id[z[j]]].count(z[flag])){ //这一步是看z[flag]和它之前的值符不符合条件(因为上面都是往后符合的) g="0";break;}}if(g=="0")cout<<0<<endl;elsecout<<1<<" "<<g<<endl;}cout<<endl;}return 0;}
- zoj 3601 Unrequited Love(STL,灵活题)
- ZOJ 3601 Unrequited Love【STL】
- ZOJ 3601 Unrequited Love
- zoj 3601 Unrequited Love
- ZOJ 3601 Unrequited Love
- ZOJ 3601 Unrequited Love
- zoj 3601unrequited Love
- ZOJ 3601 Unrequited Love
- ZOJ Unrequited Love 图论+STL
- ZOJ-3601-Unrequited Love【9th浙江省赛】【模拟】【STL】
- ZOJ 3601Unrequited Love(模拟)
- zoj 3310 - Unrequited Love
- ZOJ 3601 9th省赛 B Unrequited Love【模拟】
- zoj 4704 Unrequited Love 贪心 孤独者
- ZOJ 8th Anniversary Contest Unrequited Love
- Unrequited Love
- ZOJ3310 Unrequited Love
- ZOJ3601-Unrequited Love
- IOS中自动布局autoresizing
- 删除链表中的重复节点、剩余节点逆序输出
- CodeForces 514D R2D2 and Droid Army
- 编程之美3.3——类似——两个字符串的最长公共子序列(LCS)
- 【树形dp】Codeforces 238C World Eater Brothers
- zoj 3601 Unrequited Love(STL,灵活题)
- Python学习笔记
- 二叉查找树
- mongoose 实现DBRef查找所有子类信息
- 学习使用Git和远程代码库,已亲自试用,非常好
- 走进微信的神奇世界--数据的发送和接收
- 数字图像处理的研究方法
- MFC 定时器OnTimer的使用|string转为LPCTSTR的乱码问题
- Android Activity的生命周期