ZCMU新人训练赛B
来源:互联网 发布:数据平台开发工程师 编辑:程序博客网 时间:2024/06/05 09:46
B - Unrequited Love ZOJ - 3601
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.
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
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<map>
#include<climits>
using namespace std;
const int maxn=30090;
map<string,int> mp;
set<int> s[maxn];
int sum,n,m,q,t;
string x[maxn];
int get(string ch)
{
if(!mp.count(ch))
mp[ch]=sum++;
return mp[ch];
}
int main()
{
scanf("%d",&t);
int i,j;
while(t--)
{
scanf("%d%d%d",&n,&m,&q);
mp.clear();//清零
for(i=0;i<maxn;i++)
s[i].clear();//清零
string ch;
int a,k;
sum=0;
for(i=0;i<n+m;i++)
{
cin>>ch>>a;
k=get(ch);
for(j=0;j<a;j++)
{
cin>>ch;
s[k].insert(get(ch));
}
}
while(q--)
{
int o;
scanf("%d",&o);
for(i=0;i<o;i++)
cin>>x[i];
string p=x[0];
k=0;
for(i=1;i<o;i++)
{
if(!s[get(x[k])].count(get(x[i]))||s[get(x[i])].count(get(x[k])))
{
k=i;
p=x[i];
}
}
for(i=0;i<k;i++)
{
if(!s[get(x[k])].count(get(x[i]))||s[get(x[i])].count(get(x[k])))
{
p=" ";
break;
}
}
if(p==" ")
printf("0\n");
else
cout<<1<<" "<<p<<endl;
}
printf("\n");
}
return 0;
}
- ZCMU新人训练赛B
- ZCMU新人训练赛B
- ZCMU新人训练赛A
- ZCMU新人训练赛J
- ZCMU新人训练赛K
- ZCMU新人训练赛A
- ZCMU新人训练赛A
- ZCMU新人训练赛F
- ZCMU新人训练赛I
- ZCMU新人训练赛J
- ZCMU-训练赛-A
- ZCMU-训练赛-Primary Arithmetic
- ZCMU-训练赛-Problem A: Freckles
- ZCMU-校赛B-1777
- ZCMU—B
- TJU训练赛—B
- ZCMU-1861-zbj的a+b
- ZCMU-1107: 迟来的A+B
- jvm java回收机制
- Linux 软磁盘阵列和磁盘配额
- 【注】【精】【火】博主考研去了,现在的博文都是以前的笔记或者算法。
- maven 安装 记录一下
- LeetCode 53 Maximum Subarray
- ZCMU新人训练赛B
- Sublime Text 连接 FTP/SFTP
- 排序算法之快速排序
- 566. Reshape the Matrix
- Hadoop2.6.0运行mapreduce之Uber模式验证 标签: hadoopmapreduce源码uberjava 2016-05-05 14:55 19815人阅读 评论(2) 收藏 举报
- Hadoop 新 MapReduce 框架 Yarn 详解
- 3.Android硬件访问服务编写APP代码
- Linux下安装及使用sqlite3数据库
- SpringMVC学习系列(2) 之 经典的HelloWorld实现