暴力/set Codeforces Round #291 (Div. 2) C. Watto and Mechanism
/*
set的二分查找
如果数据规模小的话可以用O(n^2)的暴力想法
否则就只好一个一个的换(a, b, c),在set容器找相匹配的
*/
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std; int main(void)
{
//freopen ("C.in", "r", stdin); set<string> s;
string tmp;
int n, m, mx; while (cin >> n >> m)
{
mx = -;
s.clear ();
for (int i=; i<=n; ++i)
{
cin >> tmp;
s.insert (tmp);
int len = tmp.size ();
mx = max (mx, len);
}
if (n * m * mx < 1e8)
{
for (int j=; j<=m; ++j)
{
cin >> tmp;
int cnt = ;
set<string>::iterator it;
for (it=s.begin (); it!=s.end (); ++it)
{
if (it->size () == tmp.size ())
{
cnt = ;
for (int j=; j<it->size (); ++j)
{
if ((*it)[j] != tmp[j]) cnt++;
if (cnt > ) break;
}
if (cnt == ) break;
}
}
if (cnt == ) cout << "YES" << endl;
else cout << "NO" << endl;
}
continue;
} for (int i=; i<=m; ++i)
{
cin >> tmp;
bool flag = false;
for (int j=; tmp[j]!='\0'; ++j)
{
if (tmp[j] == 'a')
{
tmp[j] = 'b';
if (s.find (tmp) != s.end ())
{
flag = true; break;
}
tmp[j] = 'c';
if (s.find (tmp) != s.end ())
{
flag = true; break;
}
tmp[j] = 'a';
}
if (tmp[j] == 'b')
{
tmp[j] = 'a';
if (s.find (tmp) != s.end ())
{
flag = true; break;
}
tmp[j] = 'c';
if (s.find (tmp) != s.end ())
{
flag = true; break;
}
tmp[j] = 'b';
}
if (tmp[j] == 'c')
{
tmp[j] = 'a';
if (s.find (tmp) != s.end ())
{
flag = true; break;
}
tmp[j] = 'b';
if (s.find (tmp) != s.end ())
{
flag = true; break;
}
tmp[j] = 'c';
}
}
(flag) ? cout << "YES" << endl : cout << "NO" << endl;
}
} return ;
} /*
YES NO
*/
暴力/set Codeforces Round #291 (Div. 2) C. Watto and Mechanism的更多相关文章
- hash+set Codeforces Round #291 (Div. 2) C. Watto and Mechanism
题目传送门 /* hash+set:首先把各个字符串的哈希值保存在set容器里,然后对于查询的每一个字符串的每一位进行枚举 用set的find函数查找是否存在替换后的字符串,理解后并不难.另外,我想用 ...
- Codeforces Round #291 (Div. 2) C - Watto and Mechanism 字符串
[题意]给n个字符串组成的集合,然后有m个询问(0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) ,每个询问都给出一个字符串s,问集合中是否存在一个字符串t,使得s和t长度相同,并且仅有一个 ...
- Codeforces Round #291 (Div. 2) C. Watto and Mechanism [字典树]
传送门 C. Watto and Mechanism time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...
- Watto and Mechanism Codeforces Round #291 (Div. 2)
C. Watto and Mechanism time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
- 【推导】【暴力】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) C. Five Dimensional Points
题意:给你五维空间内n个点,问你有多少个点不是坏点. 坏点定义:如果对于某个点A,存在点B,C,使得角BAC为锐角,那么A是坏点. 结论:如果n维空间内已经存在2*n+1个点,那么再往里面添加任意多个 ...
- 数学 Codeforces Round #291 (Div. 2) B. Han Solo and Lazer Gun
题目传送门 /* 水题,就是用三点共线的式子来判断射击次数 */ #include <cstdio> #include <cmath> #include <string& ...
- 贪心/字符串处理 Codeforces Round #291 (Div. 2) A. Chewbaсca and Number
题目传送门 /* WA了好几次,除了第一次不知道string不用'\0'外 都是欠考虑造成的 */ #include <cstdio> #include <cmath> #in ...
- Codeforces Round #291 (Div. 2)
A 题意:给出变换规则,单个数字t可以变成9-t,然后给出一个数,问最小能够变成多少. 自己做的时候理解成了不能输出前导0,但是题目的本意是不能有前导0(即最高位不能是0,其余位数按照规则就好) 55 ...
随机推荐
- sql批量获取wordpress所有留言者的邮件地址
如果你的wordpress博客有很多读者互动的话,他们的留言都会留下具体的联系邮箱,我们如何批量导出这些联系信息呢?可以试试下面的sql语句 SELECT DISTINCT comment_autho ...
- Song Jiang's rank list
Song Jiang's rank list Time Limit:1000MS Memory Limit:512000KB 64bit IO Format:%I64d & ...
- 关于windows程序的学习及思考系列之一
1.窗口类的注册 a.windows程序中最简单的就是创建一个简单的窗口,而窗口程序的创建是基于窗口类的,窗口类决定了处理窗口消息的过程函数. b.一个窗口类可以用于创建多个窗口,也就是说窗口是窗口类 ...
- glut64位操作系统安装
64位win7下OpenGL的配置 - walkandthink的专栏 - 博客频道 - CSDN.NEThttp://blog.csdn.net/walkandthink/article/detai ...
- OpenCV入门(二)
这次主要学习了下滤波,就当复习了图像处理的知识了:http://blog.csdn.net/poem_qianmo/article/details/22745559 代码实现比较简单,但关于通过滚动条 ...
- [颓废] 改某人的WebGL light mapping demo并9xSSAA
渲染图(4k) 链接: http://pan.baidu.com/s/1bnB4Wqz 密码: 8839 2px高斯模糊+立方缩小AA: 链接: http://pan.baidu.com/s/1mg ...
- C# Dictionary和Dynamic类型
开发中需要传递变参,考虑使用 dynamic 还是 Dictionary(准确地说是Dictionary<string,object>).dynamic 的编码体验显著优于 Diction ...
- 《转》Visual Studio 2010 终极定制安装精简方法
打开VS2010安装目录下的 Setup 文件夹,找到 baseline.dat 文件和 vs_setup.pdi 文件还有一个 locdata.ini 文件,是对应的. 这些都是文本文件,用记事本就 ...
- iOS 关于UITableView的dequeueReusableCellWithIdentifier
今天看代码的时候,突然想到了以前的一个问题. 刚学ios那会儿,常会写出以下代码 - (UITableViewCell *)tableView:(UITableView *)tableView cel ...
- 使用apktool工具遇到could not decode arsc file的解决办法
问题详情: 当前环境为 win7 64位 jdk1.7 apktool.jar(版本1.5.2) apktool(版本windows-r05-ibot) 使用的反编译工具和apk文件为 反编译 ...