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的相对距离的奇偶性). ...
随机推荐
- PHP学习笔记:keditor的使用
keditor时一个免费的开源编辑器,很多公司在使用(百度编辑器也不错).最近为了做一个客户信息管理系统,在发送邮件模块用到这个编辑器,也算学习一下新的东西. 第一步:下载编辑器 到它的官网下载:ht ...
- mysql内存消耗分析
最近有些生产服务器老是mysql内存不停得往上涨,开发人员和维护反馈,用了不少的临时表,问题时常线上发生,测试又一直比较难重现. 经观察mysql内存的os占用趋势,发现从8:40开始,mysql内存 ...
- couchbase单向同步
我们知道,couchbase默认情况下就是N主的HA模式,bucket同时存储在多个节点中.如下所示: 但事实上,有些时候我们希望某些节点只能读,不能写以避免各种副作用以及分布式系统下出于管理和安全性 ...
- Android5.0新特性——阴影和剪裁(shadow)
阴影和剪裁 View的z属性 Material Design建议为了凸显布局的层次,建议使用阴影效果,并且Android L为了简化大家的工作,对View进行了扩展,能使大家非常方便的创建阴影效果: ...
- css清除浮动定位造成的异常
清除浮动是为了解决高度塌陷的问题:内层有好几个div有宽有高,并且选择了浮动定位,但是外层的div却并没有设置宽高.在非IE浏览器(如Firefox)下,当容器的高度为auto,且容器的内容中有浮动( ...
- 转:C# 使用NLog记录日志
原文:http://www.cnblogs.com/felixnet/p/5498759.html NLog是一个记录日志组件,和log4net一样被广泛使用,它可以将日志保存到文本文件.CSV.控制 ...
- maven eclipse 插件下载地址
要用的时候,搜索了半天,自己记录下 单独下载地址 http://maven.apache.org/download.cgi eclipse 更新地址 http://download.eclipse.o ...
- IOS 网络浅析-(四 get&post)
网络请求默认是get 网络请求有很多种:GET查 POST改 PUT增 DELETE删 HEAD 在平时开发中主要用的 是 get 和 post. get 获得数据 (获取用户信息) get 请 ...
- iOS8以后 UISearchController的用法
查了不少资料,都不太全,自己查看了apple文档,写了一份代码: 如下(只是界面): 1. 声明属性 @property (nonatomic, strong) UISearchController ...
- response实现验证码图片
package com.zhangbz.response; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2 ...