2014 Super Training #6 F Search in the Wiki --集合取交+暴力
原题: ZOJ 3674 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3674
题意不难理解,很容易想到用暴力,但是无从下手,不知道怎么实现。后来看了网上的代码,直接用vector和map暴力,用到了set_intersection()函数,之前也听过这个函数,但是一直没写过,于是照着他的代码打了一遍,算是见识一下这个函数了。
代码看一下就能看懂了,关键看自己能不能写出来。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdlib>
using namespace std;
#define N 10007 char name[],ss[],tips[];
int check[]; int main()
{
int n,m,i,j,a,b;
int cword,ctips,ind,ccheck;
while(scanf("%d",&n)!=EOF)
{
cword = ctips = ;
map<string,int> word;
map<string,int> tip;
map<int,string> atip;
vector<int> G[],K1,K2;
for(j=;j<=n;j++)
{
scanf("%s",name);
if(!word[name])
word[name] = ++cword; //hash
a = word[name];
getchar();
gets(ss);
ind = ;
for(i=;ss[i];i++)
{
if(ss[i] == ' ')
{
tips[ind] = '\0';
if(!tip[tips])
{
tip[tips] = ++ctips;
atip[ctips] = tips;
}
b = tip[tips];
G[a].push_back(b);
ind = ;
}
else
tips[ind++] = ss[i];
}
tips[ind] = ;
if(!tip[tips])
{
tip[tips] = ++ctips;
atip[ctips] = tips;
}
b = tip[tips];
G[a].push_back(b);
sort(G[a].begin(),G[a].end());
}
scanf("%d",&m);
getchar();
while(m--)
{
ccheck = ;
gets(ss);
ind = ;
for(i=;ss[i];i++)
{
if(ss[i] == ' ')
{
name[ind] = ;
check[ccheck++] = word[name];
ind = ;
}
else
name[ind++] = ss[i];
}
name[ind] = ;
check[ccheck++] = word[name];
K1.clear();
vector<int> ::iterator it;
for(it=G[check[]].begin();it<G[check[]].end();it++)
K1.push_back(*it);
for(i=;i<ccheck;i++)
{
K2.clear();
set_intersection(K1.begin(),K1.end(),G[check[i]].begin(),G[check[i]].end(),back_inserter(K2));
i++;
if(i >= ccheck) //last one
{
K1.clear();
for(it=K2.begin();it<K2.end();it++)
K1.push_back(*it);
break;
}
K1.clear();
set_intersection(K2.begin(),K2.end(),G[check[i]].begin(),G[check[i]].end(),back_inserter(K1));
}
//最终结果看K1
if(!K1.size())
{
puts("NO");
continue;
}
set<string> ans;
for(it=K1.begin();it<K1.end();it++)
ans.insert(atip[*it]);
set<string>::iterator st;
st = ans.begin();
cout<<*st;
for(st++;st!=ans.end();st++)
cout<<" "<<*st;
puts("");
}
}
return ;
}
2014 Super Training #6 F Search in the Wiki --集合取交+暴力的更多相关文章
- 2014 Super Training #7 F Power of Fibonacci --数学+逆元+快速幂
原题:ZOJ 3774 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3774 --------------------- ...
- 2014 Super Training #9 F A Simple Tree Problem --DFS+线段树
原题: ZOJ 3686 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3686 这题本来是一个比较水的线段树,结果一个ma ...
- 2014 Super Training #2 F The Bridges of Kolsberg --DP
原题:UVA 1172 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- 2014 Super Training #1 F Passage 概率DP
原题: HDU 3366 http://acm.hdu.edu.cn/showproblem.php?pid=3366 本来用贪心去做,怎么都WA,后来看网上原来是一个DP题. 首先按P/Q来做排 ...
- 2014 Super Training #7 E Calculate the Function --矩阵+线段树
原题:ZOJ 3772 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3772 这题算是长见识了,还从没坐过矩阵+线段树的题 ...
- 2014 Super Training #2 C Robotruck --单调队列优化DP
原题: UVA 1169 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show ...
- 2014 Super Training #1 B Fix 状压DP
原题: HDU 3362 http://acm.hdu.edu.cn/showproblem.php?pid=3362 开始准备贪心搞,结果发现太难了,一直都没做出来.后来才知道要用状压DP. 题意: ...
- 2014 Super Training #8 B Consecutive Blocks --排序+贪心
当时不知道怎么下手,后来一看原来就是排个序然后乱搞就行了. 解法不想写了,可见:http://blog.csdn.net/u013368721/article/details/28071241 其实就 ...
- 2014 Super Training #8 A Gears --并查集
题意: 有N个齿轮,三种操作1.操作L x y:把齿轮x,y链接,若x,y已经属于某个齿轮组中,则这两组也会合并.2.操作Q x y:询问x,y旋转方向是否相同(等价于齿轮x,y的相对距离的奇偶性). ...
随机推荐
- [下载] MultiBeast 6.2.1版,支持10.9 Mavericks。Mac上的驱动精灵,最简单安装驱动的方式。
下载地址1:http://pan.baidu.com/s/1i3ier9F 下载地址2:http://www.tonymacx86.com/downloads.php?do=cat&id=3 ...
- rabbitmq+ keepalived+haproxy高可用集群详细命令
公司要用rabbitmq研究了两周,特把 rabbitmq 高可用的研究成果备下 后续会更新封装的类库 安装erlang wget http://www.gelou.me/yum/erlang-18. ...
- 用js枚举实现简易菜单效果
用js枚举实现简易菜单效果,左侧显示菜单,右侧显示用户选择的菜单,一图胜千言,还是直接来张效果图吧: 以下是代码: <DOCTYPE html> <html> <head ...
- Oauth笔记
上周的工作有安全验证这一块,但不懂,只知道有几个关键字Oauth.secret-key .token.签名等.今天就查下资料做笔记. Oauth是什么 不依靠用户账号和密码就能获得访问资源权限 本质: ...
- How to install and configure Azure PowerShell
https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/ In this artic ...
- 微信CRM六大模块的详解
微信团队一直强调企业微信的主要功能是服务而非营销工具,微信5.0将公众号区分为服务号和订阅号,10月底平台为服务号开放高级接口,包括客服接口.网页授权等,可见服务是微信公众号的核心价值和方向.前一阵很 ...
- iOS多线程邂逅
.线程之间的通信 //有一个特别耗时的操作,比如说网络请求,开启子线程去请求网络,我们一般是要在主线程更新UI,如何从子线程跳转到主线程? #import "ViewController.h ...
- UnityShader之固定管线命令Combine纹理混合【Shader资料4】
Combine,纹理混合. 我们先看圣典上给的解释. 纹理在基本的顶点光照被计算后被应用.在着色器中通过SetTexture 命令来完成. SetTexture 命令在片面程序被使用时不会生效:这种模 ...
- 如何在自己的Windows系统上 架设服务器并开发网站,然后连入外网供外界访问?(JDK+Tomcat+花生壳)
<目前百度谷歌上都木有我这么完整的笔记,虽然各个部分都是来自百度的,然后自己实践,自己做截图笔记,嘻嘻 Made By HeYang> 环境:Windows 7 工具:JDK,Apache ...
- 大家一起和snailren学java-(六)复用类
“失恋了,唉,还没开始就结束了……唉……继续看java” 今天又是周末,我们来看看java的复用机制是什么情况.大家知道,代码复用非常实用,这项特性是java的一个重要的部分.那java用什么来实现的 ...