博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zjuoj 3601 Unrequited Love
阅读量:5142 次
发布时间:2019-06-13

本文共 2419 字,大约阅读时间需要 8 分钟。

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3601

 

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 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

Author: WU, Zejun

Contest: The 9th Zhejiang Provincial Collegiate Programming Contest

 

分析:

 

给定一些关系,对于每个人(男孩或女孩),列出他所喜欢的人(允许同性恋),对于每次询问(聚会),求这样一种人:他喜欢所有人,但所有人都不喜欢他

分析:简单分析可知,这种人假如存在,最多只有一个。因为假设有2个这样的人,他们彼此就与题意矛盾。故可以枚举这个人,如何快速枚举?

           对于一次聚会,先把第一个人假设为这种人,遍历其后的人,与当前这个人判断关系,若发现这个人不可能是这种人,则把当前遍历的更新为这种人。

           扫一遍后,再判断这个人是否真的是,只要和他前面所有的人判断一下即可

 

 

AC代码:

1 #include
2 #include
3 #include
4 #include
5 using namespace std; 6 const int N=30005; 7 map
M; 8 map
::iterator it; 9 set< pair
> S;10 string name[N];11 int tol,party[N];12 char na[22];13 int hash(char *s){14 it=M.find(s);15 if(it!=M.end())return it->second;16 else {17 name[++tol]=s;18 return M[s]=tol;19 }20 }21 void Cin(int x){22 int i,k,u,v;23 for(i=0;i
View Code

 

转载于:https://www.cnblogs.com/jeff-wgc/p/4472305.html

你可能感兴趣的文章
Beta 冲刺(5/7)
查看>>
网页编码
查看>>
术语抽取的程序(计算机专业术语的抽取 )java代写
查看>>
SpringMVC(九) RequestMapping请求参数
查看>>
线程简介
查看>>
我的算法学习之路
查看>>
机器学习中的相似性度量
查看>>
浏览器兼容
查看>>
SQL SERVER PIVOT与用法解释
查看>>
SQL Server数据库一直显示“正在还原”的解决方法
查看>>
机械硬盘设备硬件出现致命错误,导致请求失败资料怎样找回
查看>>
CSS3 transform 属性
查看>>
选择数组排序
查看>>
Step one : 熟悉HTML
查看>>
MVC模式(三层架构模式)
查看>>
XML解析【介绍、DOM、SAX详细说明、jaxp、dom4j、XPATH】
查看>>
day04_02 知识回顾、赋值运算符
查看>>
jQuery.load()事件使用方法详解
查看>>
jmeter学习笔记(三)
查看>>
一个Tahoma字体bug引发的思考—关于样式bug的分析流程
查看>>