2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) E
链接:http://codeforces.com/gym/101116
学弟写的,以后再补
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
map<string,int>v,ans;
vector<int>que[40020];
string b[40020];
int pre[40020],vis[40020],a[40020],c[40020],d[40020]; void dfs(int x){
if(c[x]==1) ans[b[x]]=1;
vis[x]=1;
for(int i=0;i<que[x].size();i++){
int y=que[x][i];
if(!vis[y]){
dfs(y);
}
}
} int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T,n,m,k,cnt,p;
cin>>T;
string s,s1;
while(T--){
memset(vis,0,sizeof(vis));
memset(c,0,sizeof(c));
cnt=0,p=1;
cin>>n>>m>>k;
for(int i=0;i<n;i++){
cin>>s;
if(!v[s]){
b[p]=s;
v[s]=p++;
}
d[i]=v[s];
}
for(int i=0;i<m;i++){
cin>>s;
if(!v[s]){
b[p]=s;
v[s]=p++;
}
c[v[s]]=1;
}
while(k--){
cin>>s>>s1;
if(!v[s]) {
b[p]=s;
v[s]=p++;
}
if(!v[s1]) {
b[p]=s1;
v[s1]=p++;
}
que[v[s]].push_back(v[s1]);
}
for(int i=0;i<n;i++){
if(!vis[d[i]]){
dfs(d[i]);
}
}
int f=1;
for(auto it : ans){
if(f) f=0,cout<<(it.first);
else cout<<" "<<(it.first);
}
if(!f) cout<<endl;
v.clear(),ans.clear();
for(int i=0;i<40020;i++) que[i].clear();
}
}
2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) E的更多相关文章
- 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) J
链接:http://codeforces.com/gym/101116 题意:给出n个点,要求一个矩形框将(n/2)+1个点框住,要面积最小 解法:先根据x轴选出i->j之间的点,中间的点(包括 ...
- 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) I
链接:http://codeforces.com/gym/101116 题意:选六个数,必须出现次数最多,且数字最小,如果出现7优先加入7 解法:排序,出现7优先加入7,最后再将6个数排序 #incl ...
- 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) B
链接:http://codeforces.com/gym/101116 学弟做的,以后再补 #include <iostream> #include <stdio.h> #in ...
- 2016-2017 CT S03E06: Codeforces Trainings Season 3 Episode 6(8/13)
2016-2017 CT S03E06: Codeforces Trainings Season 3 Episode 6 比赛连接: http://codeforces.com/gym/101124/ ...
- 2016-2017 CT S03E07: Codeforces Trainings Season 3 Episode 7 - HackerEarth Problems Compilation
B: 思路: 暴力,每两个判断一下; C: 思路: 容斥定理,先枚举脖子下面那个点和那个不可描述的点,算出所有的方案数,这里面有多的腿当成了脖子或者胳膊的,然后就再枚举这种情况把这些减去,又减多了; ...
- 2016-2017 CT S03E02: Codeforces Trainings Season 3 Episode 2
A HHPaint B Square Root C Interesting Places D Road to Home E Ant and apples F Square G Pair H The F ...
- 2016-2017 CT S03E06: Codeforces Trainings Season 3 Episode 6 The Baguette Master
比赛看不懂 之后不确定题意去瞄了题解,需要分类讨论?囧 之后按照队友已经ac的题意 就是求外面一圈周长,直接可以求得 #include<bits/stdc++.h> using names ...
- 2016-2017 CT S03E07: Codeforces Trainings Season 3 Episode 7
B. Pen Pineapple Apple Pen Solved. 题意:将一个序列合并成一个数. 思路:分类讨论一下, 水. #include<bits/stdc++.h> using ...
- 2014-2015 Codeforces Trainings Season 2 Episode 7 G Gophers --线段树
题意: 有n个地鼠,m个CD碟,每个CD碟有一个影响范围,范围内的地鼠都会被吵到,每次有一个操作就是移动CD碟,然后求每次被影响的地鼠有多少只. 解法: 线段树做.我们只关注地鼠有没有被吵到就可以了, ...
随机推荐
- 转:python socket编程详细介绍
Python 提供了两个基本的 socket 模块. 第一个是 Socket,它提供了标准的 BSD Sockets API. 第二个是 SocketServer, 它提供了服务器中心类,可以简化网络 ...
- 双端队列(单调队列)poj2823 区间最小值(RMQ也可以)
Sliding Window Time Limit: 12000MS Memory Limit: 65536K Total Submissions: 41844 Accepted: 12384 ...
- ACM常用算法及练习(1)
ACM常用算法及练习 第一阶段:练经典常用算法,下面的每个算法给我打上十到二十遍,同时自己精简代码,因为太常用,所以要练到写时不用想,10-15分钟内打完,甚至关掉显示器都可以把程序打出来. 1.最短 ...
- 关于GridView只显示一样的问题
如果GridView不管怎么改都只能显示一行的话,就重写GridView,自定义GridView: public class MyGridView extends GridView { public ...
- BeanFactory
Spring容器,最基本的接口就是BeanFactory 负责创建,配置,管理bean 它有一个子接口ApplicationContext并将功能扩展. 理论上bean ...
- 09---Net基础加强
复习 Person类: using System; using System.Collections.Generic; using System.Linq; using System.Text; us ...
- PAT乙级 1001. 害死人不偿命的(3n+1)猜想 (15)
1001. 害死人不偿命的(3n+1)猜想 (15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 卡拉兹(Ca ...
- [CrunchBang]中文字体美化
安装必要的字体包 sudo apt-get install ttf-droid ttf-wqy-zenhei xfonts-wqy ttf-wqy-microhei ttf-arphic-ukai t ...
- [slim] Slim - Faster, lightweight, a enginer for Ruby
URL: http://slim-lang.com/ Example: doctype html html head title Slim Examples meta name="keywo ...
- 指针二次释放(_BLOCK_TYPE_IS_VALID)
[1]_BLOCK_TYPE_IS_VALID是什么错误? (1)最简单的示例代码如下: void main() { ); delete pA; delete pA; } (2)运行后崩溃截图如下: ...