暴力/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 ...
 
随机推荐
- ACM Computer Factory(dinic)
			
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5596 Accepted: 1 ...
 - Maven 安装以及一些开发技巧
			
解压 apache-maven-3.2.5 在conf ->sites中配置repository 的路径. Eclipse 配置 maven 2. 3. 一些小BUG 或开发技巧 eclipse ...
 - 你真的会用AsyncTask吗?(一)
			
一个典型AsyncTask的. view source print? 01 public class DialogTestActivity extends Activity { 02 priv ...
 - 第14章 使用DHCP动态管理主机地址
			
章节简述: DHCP协议服务能够自动化的管理局域网内的主机IP地址,有效的提升IP地址使用率,提高配置效率,减少管理与维护成本. 学习dhcpd服务程序的使用方法并逐条讲解配置参数,完整演示自动化分配 ...
 - 使用virtualenv搭建独立的Python环境
			
virtualenv可以搭建虚拟且独立的python环境,可以使每个项目环境与其他项目独立开来,保持环境的干净,解决包冲突问题. 一.安装virtualenv virtualenv实际上是一个pyth ...
 - 【云计算】开源的Docker Registry WebUI
			
kwk/docker-registry-frontend Code Issues 9 Pull requests 6 Wiki ...
 - 利用cocostudio库函数 实现左右滑动的背包栏UI (cocos2d-x 2.2.0)
			
.h #ifndef __COMMON_COMPONENTS__ #define __COMMON_COMPONENTS__ #include "cocos2d.h" #inclu ...
 - C++ traits
			
[本文链接] http://www.cnblogs.com/hellogiser/p/cplusplus-traits.html [分析] 什么是traits?其实它并不是一个新的概念,上个世纪90年 ...
 - win10远程桌面连接
			
有的情况下,Win10设置了允许远程桌面连接后,远程主机仍然不能桌面连接到目标主机上,这时可以在目标主机上尝试如下修改: 开始-->运行->gpedit.msc->计算机配置-> ...
 - svn插件subclipse使用http代理同步svn时出现异常(解决)
			
现象描述: 对项目进行“与资源库进行同步”时弹出对话框显示以下错误信息: 同步 SVNStatusSubscriber 时报告了错误.1 中的 0 个资源已经同步. 同步 /MMonitorLogis ...