[POJ3096]Surprising Strings
[POJ3096]Surprising Strings
试题描述
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 0-pairs are ZG, GB, and BG. Since these three pairs are all different, ZGBG is 0-unique. Similarly, the 1-pairs of ZGBG are ZB and GG, and since these two pairs are different, ZGBG is 1-unique. Finally, the only 2-pair of ZGBG is ZG, so ZGBG is 2-unique. Thus ZGBG is surprising. (Note that the fact that ZG is both a 0-pair and a 2-pair of ZGBG is irrelevant, because 0 and 2 are different distances.)
Acknowledgement: This problem is inspired by the "Puzzling Adventures" column in the December 2003 issue of Scientific American.
输入
The input consists of one or more nonempty strings of at most 79 uppercase letters, each string on a line by itself, followed by a line containing only an asterisk that signals the end of the input.
输出
For each string of letters, output whether or not it is surprising using the exact output format shown below.
输入示例
ZGBG
X
EE
AAB
AABA
AABB
BCBABCC
*
输出示例
ZGBG is surprising.
X is surprising.
EE is surprising.
AAB is surprising.
AABA is surprising.
AABB is NOT surprising.
BCBABCC is NOT surprising.
数据规模及约定
见“输入”
题解
n2 枚举一下长度和字母对,然后把字母对哈希一下,看是否出现重复。打个时间戳可以节省时间。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; #define maxn 85
#define maxm 800
char S[maxn];
int has[maxm]; int main() {
while(scanf("%s", S + 1) == 1) {
int n = strlen(S + 1);
if(n == 1 && S[1] == '*') break;
bool ok = 1;
memset(has, 0, sizeof(has));
for(int l = 1; l < n; l++) {
for(int i = 1; i + l <= n; i++) {
int x = (S[i] - 'A') * 26 + S[i+l] - 'A';
if(has[x] == l){ ok = 0; break; }
has[x] = l;
}
if(!ok) break;
}
printf("%s%s\n", S + 1, ok ? " is surprising." : " is NOT surprising.");
} return 0;
}
[POJ3096]Surprising Strings的更多相关文章
- 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 ...
- Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Description ...
- [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 ...
- POJ3096:Surprising Strings(map)
http://poj.org/problem?id=3096 for循环真是奇妙! #include <string.h> #include <stdio.h> #includ ...
随机推荐
- webView(简单的浏览器)
#import "MJViewController.h" @interface MJViewController () <UISearchBarDelegate, UIWeb ...
- 多态 oc c++ 与oc category
多态是函数调用的动态绑定技术: c++动态绑定依赖于this指针与虚函数表. 虚函数表的排序规则: 1)虚函数按照其声明顺序放于表中. 2)父类的虚函数在子类的虚函数前面. 3)如果子类重写了父类的虚 ...
- SimpleDateFormat 12小时制以及24小时制的写法
有些代码按了复制键没有效果,但是其实已经复制到剪贴板上面了,大家请注意哦! 我的文章有时会稍有修改,转载请注明出处哦! 原文地址:SimpleDateFormat 12小时制以及24小时制的写法 去代 ...
- 获取网卡的MAC地址原码;目前支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址(服务器端)
<?php class GetMacAddr{ var $return_array = array(); // 返回带有MAC地址的字串数组 var $mac_addr; function Ge ...
- HTML学习笔记——标签设置格式
1>标签设置格式 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...
- 比较详细Python正则表达式操作指南(re使用)
比较详细Python正则表达式操作指南(re使用) Python 自1.5版本起增加了re 模块,它提供 Perl 风格的正则表达式模式.Python 1.5之前版本则是通过 regex 模块提供 E ...
- SCI/EI期刊投稿 Reply Letter 常用格式总结
SCI/EI期刊投稿Reply Letter常用格式总结 整个论文投稿的过程中,会遇到各种问题,需要我们向主编询问或是回复.下面主要总结了responses to the comme ...
- linux端口详解
Linux端口总结如下: 0|无效端口,通常用于分析操作系统 1|传输控制协议端口服务多路开关选择器 2|管理实用程序 3|压缩进程 5|远程作业登录 7|回显 9|丢弃 11|在线用户 13|时间 ...
- oracle union 注入工具
'***********************************************************************************************'ora ...
- C-指针
//格式:变量类型 *变量名//定义了一个指针变量p//指针变量只能存储地址//指针就一个作用:能够根据一个地址值,访问对应的存储空间//指针变量p前面的int:指针变量p只能指向int类型的数据in ...