题目传送门

 /*
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. cocos基础教程(2)Window环境下搭建

    第一步:开始安装VS2012  第二步:下载Cocos2d-x 3.4源码  配置环境变量 COCOS_CONTROL = E:\cocos2d-x-3.4\tools\cocos2d-console ...

  2. Java笔记--泛型总结与详解

    泛型简介: 在泛型没有出来之前,编写存储对象的数据结构是很不方便的.如果要针对每类型的对象写一个数据结构,     则当需要将其应用到其他对象上时,还需要重写这个数据结构.如果使用了Object类型, ...

  3. Tomcat打包时多项目共享jar和精确指定jar版本

    在产品打包发布时一个tomcat中如果存在多个war,部署的一般方式是部署到%TOMCAT_HOME%/webapps目录下,目录结构遵循J2EE规范,把引用的jar放到%TOMCAT_HOME%/w ...

  4. hrb 2134 素数

    分拆素数和 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 176(99 users) Total Accepted: 106(93 u ...

  5. CI邮箱中SMTP的一些端口

    介绍其他几个常用邮箱设置,并以网易126邮箱为例,发图.        一.新浪邮箱(1)新浪邮箱自08年6月分服务器被攻击后开始对pop取件频率进行了严格**,同时新注册的用户需要手动才能开通pop ...

  6. [转]sql语句中出现笛卡尔乘积 SQL查询入门篇

    本篇文章中,主要说明SQL中的各种连接以及使用范围,以及更进一步的解释关系代数法和关系演算法对在同一条查询的不同思路. 多表连接简介 在关系数据库中,一个查询往往会涉及多个表,因为很少有数据库只有一个 ...

  7. Swap Two Nodes in Linked List

    Given a linked list and two values v1 and v2. Swap the two nodes in the linked list with values v1 a ...

  8. FastReport安装说明(中文版)

    FastReport安装说明(中文版) 内容列表 I. IntroductionI. 介绍II. Manual installing of the FastReport packagesII. 手动安 ...

  9. Java for LeetCode 056 Merge Intervals

    Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8, ...

  10. codeforces B. Simple Molecules 解题报告

    题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...