Unrequited Love
来源:互联网 发布:网络综艺为什么这么火 编辑:程序博客网 时间:2024/05/24 01:38
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.
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.
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.
<h4< dd="">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
001 BoyB000
找出一个人--->这个人喜欢聚会里面的每个人,但是聚会里的每个人不喜欢他。
没有输出0;
思路:用STL和count函数。 还有很容易得出每次聚会最多只有一个人符合条件。
#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<set>#include<map>#include<vector>using namespace std;int main(){ int n,m,i,j,k,t,p,q,n1,n2,n3,n4; scanf("%d",&t); while(t--) { string name,name1,g; string z[30010]; map<string,int>id; set<string>s[36000]; scanf("%d %d %d",&n,&m,&p); q=-1; for(i=0; i<n+m; i++) { cin>>name1; if(id.count(name1)==0) { q++; id[name1]=q;//把名字转化为数字存入map里面。 } scanf("%d",&k); for(j=0; j<k; j++) { cin>>name; s[id[name1]].insert(name); } } for(j=0; j<p; j++) { scanf("%d",&n1); for(i=0; i<n1; i++) { cin>>z[i]; } g=z[0]; int f=0; for(i=1; i<n1; i++) { if(s[id[z[f]]].count(z[i])==0||s[id[z[i]]].count(z[f])) { f=i; g=z[i]; } } //cout<<g<<endl; int flag=0; for(i=0; i<f; i++) { if(s[id[z[i]]].count(z[f])||s[id[g]].count(z[i])==0) { g="0"; break; } } } if(g=="0") cout<<0<<endl; else cout<<1<<" "<<g<<endl; cout<<endl; } return 0;}
- Unrequited Love
- ZOJ3310 Unrequited Love
- ZOJ 3601 Unrequited Love
- zoj 3601 Unrequited Love
- ZOJ 3601 Unrequited Love
- ZOJ 3601 Unrequited Love
- zoj 3310 - Unrequited Love
- zoj 3601unrequited Love
- ZOJ 3601 Unrequited Love
- ZOJ3601-Unrequited Love
- ZOJ Unrequited Love 图论+STL
- ZOJ 3601Unrequited Love(模拟)
- ZOJ 3601 Unrequited Love【STL】
- zoj 3601 Unrequited Love(STL,灵活题)
- zoj 4704 Unrequited Love 贪心 孤独者
- ZOJ 8th Anniversary Contest Unrequited Love
- ZOJ-3601-Unrequited Love【9th浙江省赛】【模拟】【STL】
- ZOJ 3601 9th省赛 B Unrequited Love【模拟】
- 通达oa破解版下载|通达oa破解补丁下载|通达oa破解补丁
- Linux系统环境变量文件(/etc/profile)设置后无法使用vim、vi等命令原因以及解决方法
- VMware安装Linux-Ubuntu系统(一)
- JDK安装及环境配置+tomcat安装
- Java Hotspot G1 GC的一些关键技术
- Unrequited Love
- 【51Nod1257】背包问题 V3
- 剑指offer-判断平衡二叉树
- linux下使用润乾V5设计器乱码问题
- eval解析JSON中的注意点 在JS中将JSON的字符串解析成JSON数据格式,一般有两种方式: 1.一种为使用eval()函数。 2. 使用Function对象来进行返回解析。 使用eval
- 计算机修炼之路--------JavaScript法术的学习笔记(三)之JavaScript语法(二)
- hdu6138 多校2017 ac自动机or后缀数组
- Debug Knowledge Base
- poj--1961--Period