ZOJ 3601 Unrequited Love
来源:互联网 发布:单片机解密公司 编辑:程序博客网 时间:2024/05/13 12:21
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<map>#include<cmath> #include<queue> #include<string>#include<vector>#include<cstdio> #include<cstring> #include<algorithm> using namespace std;#define ms(x,y) memset(x,y,sizeof(x)) #define rep(i,j,k) for(int i=j;i<=k;i++) #define per(i,j,k) for(int i=j;i>=k;i--) #define loop(i,j,k) for (int i=j;i!=-1;i=k[i]) #define inone(x) scanf("%d",&x) #define intwo(x,y) scanf("%d%d",&x,&y) #define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z) typedef long long LL;const int low(int x) { return x&-x; }const int INF = 0x7FFFFFFF;const int mod = 1e9 + 7;const int N = 1e5 + 10;int T, n, m, x, a[N];char s[N], q[N][25];map<string, int> M;map<pair<int, int>, bool> G;int main(){for (inone(T); T--;){intwo(n, m); n += m; inone(m);M.clear(); G.clear();int cnt = 0;rep(i, 1, n){scanf("%s%d", s, &x);if (!M[s]) M[s] = ++cnt, memcpy(q[cnt], s, sizeof(q[cnt]));int k = M[s];rep(j, 1, x){scanf("%s", s);if (!M[s]) M[s] = ++cnt, memcpy(q[cnt], s, sizeof(q[cnt]));G[make_pair(k, M[s])] = true;}}rep(i, 1, m){inone(x);int k = 1;rep(j, 1, x){scanf("%s", s);a[j] = M[s];if (k == j || (G[make_pair(a[k], a[j])] && !G[make_pair(a[j], a[k])])) continue;k = j;}rep(j, 1, x){if (k == j || (G[make_pair(a[k], a[j])] && !G[make_pair(a[j], a[k])])) continue;k = 0; break;}if (k) printf("1 %s\n", q[a[k]]); else puts("0");}putchar(10);}return 0;}
- ZOJ 3601 Unrequited Love
- zoj 3601 Unrequited Love
- ZOJ 3601 Unrequited Love
- ZOJ 3601 Unrequited Love
- zoj 3601unrequited Love
- ZOJ 3601 Unrequited Love
- ZOJ 3601Unrequited Love(模拟)
- ZOJ 3601 Unrequited Love【STL】
- zoj 3601 Unrequited Love(STL,灵活题)
- zoj 3310 - Unrequited Love
- ZOJ Unrequited Love 图论+STL
- ZOJ-3601-Unrequited Love【9th浙江省赛】【模拟】【STL】
- ZOJ 3601 9th省赛 B Unrequited Love【模拟】
- zoj 4704 Unrequited Love 贪心 孤独者
- ZOJ 8th Anniversary Contest Unrequited Love
- Unrequited Love
- ZOJ3310 Unrequited Love
- ZOJ3601-Unrequited Love
- ESTabBarController
- ZOJ 3600Taxi Fare
- 十大经典数据挖掘算法
- 知识库--Separation of Identity and State 身份和状态的分离(118)
- 指针和引用
- ZOJ 3601 Unrequited Love
- 使用 flow.ci 快速发布你的项目文档
- RSA认证登录OpenShif
- 打开Tomcat服务器网页部署界面的配置发布JavaWeb项目
- sql如何查询表的第一条记录和最后一条记录
- 山东大学软件学院数据结构课程设计第一题python实现
- android6.0新权限获取(以相机举例)
- ZOJ 3603 Draw Something Cheat
- ss问题