暴力/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 ...
随机推荐
- dedecms文章标题是在哪个数据库表?要批量替换关键词
一位小MM刚接触dedecms没多久还不熟悉后台的操作,她说改dedecms文章中的品牌名改到手酸,问ytkah是否有批量替换关键词的方法,教了她dedecms后台批量替换文章中的关键词方法,她高兴坏 ...
- 还是畅通工程(MST)
还是畅通工程 Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- Socket 多线程FTP软件开发
Socket具体还可见360云中文档记载 Socket是一个非常古老的协议了 1970年 Socket.AF_Unix======AF意思是 addressFamily 地址簇 Import os ...
- [Effective JavaScript 笔记]第18条:理解函数调用、方法调用及构造函数调用之间的不同
面向对象编程中,函数.方法.类的构造函数是三种不同的概念. JS中,它们只是单个构造对象的三种不同的使用模式. 三种不同的使用模式 函数调用 function hello(username){ ret ...
- ruby on rails揭开route路由的真面目
文章是从我的个人主页上粘贴过来的, 大家也可以访问我的主页 www.iwangzheng.com 最近的项目里发现一个问题,大师和pp写的index页面就好使,我写index页面就不往index页面跳 ...
- linux下cp目录时排除一个或者多个目录的方法
说明:/home目录里面有data目录,data目录里面有a.b.c.d.e五个目录,现在要把data目录里面除过e目录之外的所有目录拷贝到/bak目录中 系统运维 www.osyunwei.com ...
- 特殊表达式的意义[c++ special expressions]
[本文链接] http://www.cnblogs.com/hellogiser/p/special-expressions.html x&(x-1)表达式的意义: 统计二进制中1的个数. ...
- Android 中的AsyncTask
在后台下载图片,下载完成后更新UI是一个很常见的需求.在没有AsyncTask类之前,我们需要写许多thread和Handler的代码去实现这个功能,有了AsyncTask,一切变得简单了.下面摘抄谷 ...
- Adobe Flash Player 因过期而遭到阻止 更新插件 运行一次 解决方法
老机器运行 10.3.183.90 比较流畅 可是 Chrome 浏览器提示 Adobe Flash Player 因过期而遭到阻止 更新插件 运行一次 每次单击 运行一次 才运行,这样每次提醒很烦人 ...
- Java for LeetCode 189 Rotate Array
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...