暴力/set Codeforces Round #291 (Div. 2) C. Watto and Mechanism
题目传送门
1 /* 2 set的二分查找 3 如果数据规模小的话可以用O(n^2)的暴力想法 4 否则就只好一个一个的换(a, b, c),在set容器找相匹配的 5 */ 6 #include <cstdio> 7 #include <cmath> 8 #include <string> 9 #include <cstring> 10 #include <iostream> 11 #include <algorithm> 12 #include <map> 13 #include <set> 14 #include <vector> 15 using namespace std; 16 17 int main(void) 18 { 19 //freopen ("C.in", "r", stdin); 20 21 set<string> s; 22 string tmp; 23 int n, m, mx; 24 25 while (cin >> n >> m) 26 { 27 mx = -1; 28 s.clear (); 29 for (int i=1; i<=n; ++i) 30 { 31 cin >> tmp; 32 s.insert (tmp); 33 int len = tmp.size (); 34 mx = max (mx, len); 35 } 36 if (n * m * mx < 1e8) 37 { 38 for (int j=1; j<=m; ++j) 39 { 40 cin >> tmp; 41 int cnt = 0; 42 set<string>::iterator it; 43 for (it=s.begin (); it!=s.end (); ++it) 44 { 45 if (it->size () == tmp.size ()) 46 { 47 cnt = 0; 48 for (int j=0; j<it->size (); ++j) 49 { 50 if ((*it)[j] != tmp[j]) cnt++; 51 if (cnt > 1) break; 52 } 53 if (cnt == 1) break; 54 } 55 } 56 if (cnt == 1) cout << "YES" << endl; 57 else cout << "NO" << endl; 58 } 59 continue; 60 } 61 62 for (int i=1; i<=m; ++i) 63 { 64 cin >> tmp; 65 bool flag = false; 66 for (int j=0; tmp[j]!='\0'; ++j) 67 { 68 if (tmp[j] == 'a') 69 { 70 tmp[j] = 'b'; 71 if (s.find (tmp) != s.end ()) 72 { 73 flag = true; break; 74 } 75 tmp[j] = 'c'; 76 if (s.find (tmp) != s.end ()) 77 { 78 flag = true; break; 79 } 80 tmp[j] = 'a'; 81 } 82 if (tmp[j] == 'b') 83 { 84 tmp[j] = 'a'; 85 if (s.find (tmp) != s.end ()) 86 { 87 flag = true; break; 88 } 89 tmp[j] = 'c'; 90 if (s.find (tmp) != s.end ()) 91 { 92 flag = true; break; 93 } 94 tmp[j] = 'b'; 95 } 96 if (tmp[j] == 'c') 97 { 98 tmp[j] = 'a'; 99 if (s.find (tmp) != s.end ()) 100 { 101 flag = true; break; 102 } 103 tmp[j] = 'b'; 104 if (s.find (tmp) != s.end ()) 105 { 106 flag = true; break; 107 } 108 tmp[j] = 'c'; 109 } 110 } 111 (flag) ? cout << "YES" << endl : cout << "NO" << endl; 112 } 113 } 114 115 return 0; 116 } 117 118 /* 119 YES NO 120 */
转载于:https://www.cnblogs.com/Running-Time/p/4366757.html
暴力/set Codeforces Round #291 (Div. 2) C. Watto and Mechanism相关推荐
- hash+set Codeforces Round #291 (Div. 2) C. Watto and Mechanism
题目传送门 1 /* 2 hash+set:首先把各个字符串的哈希值保存在set容器里,然后对于查询的每一个字符串的每一位进行枚举 3 用set的find函数查找是否存在替换后的字符串,理解后并不难. ...
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
题目传送门 1 /* 2 题意:删除若干行,使得n行字符串成递增排序 3 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 4 */ 5 /************* ...
- CodeForces Round #291 Div.2
A. Chewbaсca and Number 感觉这道题巨坑,如果题中加粗标出来的输出得是正数算小坑的话.有个巨坑就是 the final number shouldn't start with a ...
- 【暴力】Codeforces Round #398 (Div. 2) A. Snacktower
题意不复述. 用个bool数组记录一下,如果某一天,当前剩下的最大的出现了的话,就输出一段. #include<cstdio> using namespace std; int n; bo ...
- acm-(模拟、暴力枚举)Codeforces Round #664 (Div. 1) A. Boboniu Chats with Du
传送门 将元素分为两类,大于mmm的和小于等于mmm的. 对于大于mmm的,我们将最大的那个放在序列末端,然后枚举其它元素有多少个能产生贡献,假设有xxx个能产生贡献,那么这xxx个元素还会消耗xdx ...
- Codeforces Round #291 (Div. 2)
A 简单题 B 简单题 C 求改变一个字母的单词是否出现过 字典树+dfs D k次射击 每次可以把一列都减小1 总共m列 m列都为0就被破坏掉 问最多连续多少个被破坏掉 二分答案 在用数据结构询问某 ...
- Codeforces Round #400 (Div. 1 + Div. 2, combined) 776E. The Holmes Children(待翻译)
Codeforces Round #241 (Div. 2) 514C Watto and Mechanism ≤,≠,≥<> 时间限制:1S / 空间限制:256MB [在线测试提交传送 ...
- Codeforces Round #743 (Div. 2) E. Paint 区间dp + 暴力
传送门 文章目录 题意: 思路: 题意: 给你一个有nnn个像素的图像,每个像素都有一个颜色aia_iai,保证每种颜色的图像不会超过202020个.你现在每次可以选择一个颜色,并选择一段连续的像素 ...
- Codeforces Round #588 (Div. 2) E. Kamil and Making a Stream 数学 + 暴力
传送门 文章目录 题意: 思路: 题意: 给你一颗树,其中根是111,每个点有一个点权,求每个点到根的所有路径的gcdgcdgcd之和. n≤1e5n\le1e5n≤1e5 思路: 一看到以为是个点分 ...
- Codeforces Round #593 (Div. 2) D. Alice and the Doll 暴力 + 二分
传送门 文章目录 题意: 思路: 题意: 思路: 还以为这个题有什么高深的算法,结果就是个暴力. 由于n∗mn*mn∗m达到了1e101e101e10的级别,所以直接暴力肯定是不行的,考虑有很多空格, ...
最新文章
- 【POJ】1308 Is It A Tree?((并查集 + set)or (map))
- maven 如何看jar是否被修改_如何在线修改jar文件
- oracle11g32位安装流程_Oracle 11g服务器安装详细步骤图文详解
- c++: 读取访问权限冲突0xcdcdcdcd_微信读取不到本地相册
- SAP Cloud for Customer使用工作流(workflow)实现邮件自动通知功能
- vue中使用Ueditor编辑器 -- 1
- 计算机图形学入门:什么是光线追踪?
- MacBook Pro 2017版(带multi-touch bar)安装使用 windows10
- 10款最佳Python开发工具推荐,每一款都是神器!
- 常微分和偏微分方程的区别是啥?
- win10 无法安全地连接到此页面 TLS安全设置未设置为默认 该怎么办? 无法访问此页面
- 手机图片到底要做多宽才可以适应所有手机屏幕的尺寸?
- 函数参数缺省值/默认值
- OFDMA,LFDMA以及IFDMA的PAPR对比仿真
- qq音乐登录页面的html代码,musicQQ音乐协议登录源码
- 查看Hadoop集群的基本信息
- opc读取ab的plc数据_IFIX与AB PLC通过opc方式连接的方法(ZZ)
- 安卓APP(3)——安卓布局控件
- 学生宿舍6路控制电表智能模块的功能介绍
- 你不得不知道的设置canvas画布的宽和高的坑