Surprising Strings
Surprising Strings
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: Accepted:
Description The D-pairs of a string of letters are the ordered pairs of letters that are distance D from each other. A string is D-unique if all of its D-pairs are different. A string is surprising if it is D-unique for every possible distance D. Consider the string ZGBG. Its -pairs are ZG, GB, and BG. Since these three pairs are all different, ZGBG is -unique. Similarly, the -pairs of ZGBG are ZB and GG, and since these two pairs are different, ZGBG is -unique. Finally, the only -pair of ZGBG is ZG, so ZGBG is -unique. Thus ZGBG is surprising. (Note that the fact that ZG is both a -pair and a -pair of ZGBG is irrelevant, because and are different distances.) Acknowledgement: This problem is inspired by the "Puzzling Adventures" column in the December issue of Scientific American. Input The input consists of one or more nonempty strings of at most uppercase letters, each string on a line by itself, followed by a line containing only an asterisk that signals the end of the input. Output For each string of letters, output whether or not it is surprising using the exact output format shown below. Sample Input ZGBG
X
EE
AAB
AABA
AABB
BCBABCC
*
Sample Output ZGBG is surprising.
X is surprising.
EE is surprising.
AAB is surprising.
AABA is surprising.
AABB is NOT surprising.
BCBABCC is NOT surprising.
Source Mid-Central USA
#include <iostream>
#include <cstdio>
#include<set>
#include <vector>
#include <cstring>
#include <list>
#include <queue>
#include <algorithm>
#include<functional>
#include <stack>
#define MAXN 200 + 3
#define INF 0x3f3f3f3f
using namespace std;
//直接枚举+hash+set 随便过
char s[MAXN];
inline int Hash(char a, char b)
{
return (a - 'a') * + b - 'a';
}
int main()
{
ios::sync_with_stdio();
while (cin >> s, s[] != '*')
{
set<int> S;
int L = strlen(s);
int l;
for (l = ; l < L; l++)
{
S.clear();
for (int i = ; i + l < L; i++)
S.insert(Hash(s[i], s[i + l]));
if (S.size() != L - l)
break;
}
if (l == L)
cout << s << " is surprising." << endl;
else
cout << s << " is NOT surprising." << endl;
}
return ;
}
Surprising Strings的更多相关文章
- [POJ3096]Surprising Strings
[POJ3096]Surprising Strings 试题描述 The D-pairs of a string of letters are the ordered pairs of letters ...
- C - Surprising Strings
C - Surprising Strings 题意:输入一段字符串,假设在同一距离下有两个字符串同样输出Not surprising ,否 ...
- HDOJ 2736 Surprising Strings
Surprising Strings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- POJ 3096 Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5081 Accepted: 333 ...
- HDU 2736 Surprising Strings
Surprising Strings Time Limit:1000MS Memory Limit:65536KB 64 ...
- 【字符串题目】poj 3096 Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6193 Accepted: 403 ...
- [ACM] POJ 3096 Surprising Strings (map使用)
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5783 Accepted: 379 ...
- POJ 3096:Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6258 Accepted: 407 ...
- hdu 2736 Surprising Strings(类似哈希,字符串处理)
重点在判重的方法,嘻嘻 题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> int ...
随机推荐
- SpringMvc如何将Url 映射到 RequestMapping (一)
SpringMvc Url 匹配规则详解 最近开始阅读Spring 源码,虽然用了很久的spring ,但是没有真正的分析过Spring时如何工作的.今天重 MVC 的Url匹配规则开始进行Sprin ...
- Python学习 Day 1-简介 安装 Hello world
简介 Python(英语发音:/ˈpaɪθən/), 是一种面向对象.解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年,Python 源 ...
- Java对Redis基本使用
1 引入jar包 java是通过Jedis对redis进行操作的,首先引入jedis.jar <dependency> <groupId>redis.clients</g ...
- iTOP-6818开发板设置NFS共享目录的实现
NFS 共享目录的制作过程.主要分为两个步骤:1.搭建 NFS 服务器2.配置内核. NFS 是 Network FileSystem 的缩写,是由 SUN 公司研制的 UNIX 表示层协议(pres ...
- jQuery 首页搜索区域模块随页面滑动而变化
/*搜索区块的颜色变化*/ function search(){ var searchBox = document.querySelector('.m_head'); var bannerBox = ...
- MFC_VS清理器
VS清理器 界面 工程目录 列表控件ID改名IDC_FILELIST 绑定变量m_FileList 属性设置Accept Files 设置True 成员添加 // 用于保存待遍历的目录 vector& ...
- width:100px; min-width:100% 解释:宽度大于100px 就是100% 小于100px 就是100像素
<div style="width:100px; background-color: aqua; min-width:100%">kkk</div>
- du查看文件大小
du+文件名就可以查看文件大小 du+ -h + 文件名也是查看文件大小,只是-h会将文件大小转换成M,G等格式
- linux 小键盘 数字键盘 wiki
https://wiki.archlinux.org/index.php/Activating_Numlock_on_Bootup_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96 ...
- PLSQL连接Oracle 报错ORA-12154:TNS:无法解析指定的连接标识符
原因是图中第三行数据库应该填ip地址,我填了数据库名! 之前不懂原理,现来填坑,并不是应该填ip,而是填tnsname.ora中配置的名字(红框部分)