题目传送门

 /*
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的更多相关文章

  1. hash+set Codeforces Round #291 (Div. 2) C. Watto and Mechanism

    题目传送门 /* hash+set:首先把各个字符串的哈希值保存在set容器里,然后对于查询的每一个字符串的每一位进行枚举 用set的find函数查找是否存在替换后的字符串,理解后并不难.另外,我想用 ...

  2. Codeforces Round #291 (Div. 2) C - Watto and Mechanism 字符串

    [题意]给n个字符串组成的集合,然后有m个询问(0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) ,每个询问都给出一个字符串s,问集合中是否存在一个字符串t,使得s和t长度相同,并且仅有一个 ...

  3. 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 ...

  4. 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

    题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...

  5. 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 ...

  6. 【推导】【暴力】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个点,那么再往里面添加任意多个 ...

  7. 数学 Codeforces Round #291 (Div. 2) B. Han Solo and Lazer Gun

    题目传送门 /* 水题,就是用三点共线的式子来判断射击次数 */ #include <cstdio> #include <cmath> #include <string& ...

  8. 贪心/字符串处理 Codeforces Round #291 (Div. 2) A. Chewbaсca and Number

    题目传送门 /* WA了好几次,除了第一次不知道string不用'\0'外 都是欠考虑造成的 */ #include <cstdio> #include <cmath> #in ...

  9. Codeforces Round #291 (Div. 2)

    A 题意:给出变换规则,单个数字t可以变成9-t,然后给出一个数,问最小能够变成多少. 自己做的时候理解成了不能输出前导0,但是题目的本意是不能有前导0(即最高位不能是0,其余位数按照规则就好) 55 ...

随机推荐

  1. 利用zabbix监控某个目录大小

    近期,因为JMS的消息堆积导致ApacheMQ频率故障(消息没有被消费掉,导致其数据库达到1.2G,JMS此时直接挂掉),很是郁闷!刚好自 己在研究zabbix.既然zabbix如此强大,那么它可以监 ...

  2. 右移>> 和 左移<<

    一个int占四个字节,也就是32位,这样的话1不论左移还是右移32位仍旧移到原来的位置,就仍旧是1了. 右移是除,左移是乘.1除1除32次和1乘1乘32次当然都还是1了. 移位操作的简单计算方法 &g ...

  3. 【OpenStack】OpenStack系列10之Horizon详解

    一.参考其他资料即可.可以采用haproxy+apache+horizon方式部署,haproxy/httpd支持ssl.

  4. Remove Duplicates from Sorted List | & ||

    Remove Duplicates from Sorted List I Given a sorted linked list, delete all duplicates such that eac ...

  5. (原创)Python文件与文件系统系列(4)——文件描述字操作

    文件描述字(file descriptor,fd)是系统中用来唯一记录当前已经打开的文件的标识号,fd是一个整数. 除了file对象外,Python还提供对fd的操作,对fd的操作更加底层,fd和Py ...

  6. Java for LeetCode 078 Subsets

    Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must ...

  7. 快速排序模板qsort(转载)

     qsort  用 法: void qsort(void *base, int nelem, int width, int (*fcmp)(const void *,const void *)); 各 ...

  8. codeforces 474D.Flowers 解题报告

    题目链接:http://codeforces.com/problemset/problem/474/D 题目意思:Marmot 吃两种类型的花(实在难以置信呀--):red 或者 white,如果要吃 ...

  9. 【USACO】namenum

    //开始傻×了 受题目形容的误导 一心想生成所有可能的 字符串组合 之后查找非常慢 //听了同学的 将5000个dict里的字符串 转换成char型数组(不能直接用int 会越界)直接用输入的数据对着 ...

  10. hadoop命令备忘

    hadoop dfsadmin -safemode get 查看namenode是否处于安全模式 hadoop dfsadmin -report 显示文件系统的统计信息,以及所连接的各个datanod ...