ZOJ 3601 Unrequited Love【STL】
来源:互联网 发布:c 知乎 编辑:程序博客网 时间:2024/05/27 20:03
Unrequited Love Time Limit: 16 Seconds Memory Limit: 131072 KB 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 than20
. 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 SSample Output
001 BoyB000
注意:①king如果有只有一个,因为出现king就表示着剩余的人不是喜欢全部的人;②先假定第一个人a满足条件,从第二个人开始遍历。若不满足条件,则把a置成b,而对于跳过的人,必定存在一个他不爱的人,这就是当时的a,不然,a就要等于他。所以最后对a进行判断即可,包括爱与被爱的关系。
#include<cstdio>#include<math.h>#include<cstring>#include<climits>#include<string>#include<queue>#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<climits>#include<string>#include<queue>#include<stack>#include<set>#include<map>#include<algorithm>using namespace std;#define rep(i,j,k)for(i=j;i<k;i++)#define per(i,j,k)for(i=j;i>k;i--)#define MS(x,y)memset(x,y,sizeof(x))#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define ll long long#define abs(x) (x>0?x:-x)const int INF=0x7ffffff;const ll MAX=1e18;int main(){int t;cin>>t;while(t--){ set<string> x[30001]; map<string,int> id; string z[30001]; string h,w; int n,m,a,b; int i,j,k;cin>>n>>m>>a;int p=-1;for(i=0;i<n+m;++i){cin>>h>>b;//if(id.count(h)==0) id[h]=++p;for(j=0;j<b;++j){cin>>w;x[id[h]].insert(w);}}for(i=0;i<a;++i){cin>>b;for(j=0;j<b;++j)cin>>z[j];string g=z[0];int flag=0;for(j=1;j<b;++j){if(!x[id[g]].count(z[j])||x[id[z[j]]].count(g)){g=z[j];flag=j;} }for(j=0;j<flag;++j){if(!x[id[g]].count(z[j])||x[id[z[j]]].count(g)){break;}}if(j!=flag)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
- UVA 156 Ananagrams(stl,map,set)
- 字幕文件批量重命名脚本(二) —— Linux
- 项目及人员管理系统
- What is purpose of @ConditionalOnProperty annotation?
- 解决viewpager自动轮播速度变快的问题
- ZOJ 3601 Unrequited Love【STL】
- 十六、Hive 表的创建及测试
- python机器学习库入门之pandas
- 原型模式——prototype
- 高性能业务架构解决方案(LVS+Keepalived)
- Day 1
- hoj 2662
- 【Spring框架】Spring IOC 回忆总结
- PAT-A 1046. Shortest Distance (20)