[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的更多相关文章

  1. C - Surprising Strings

                                   C - Surprising Strings 题意:输入一段字符串,假设在同一距离下有两个字符串同样输出Not surprising ,否 ...

  2. HDOJ 2736 Surprising Strings

    Surprising Strings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. POJ 3096 Surprising Strings

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5081   Accepted: 333 ...

  4. HDU 2736 Surprising Strings

                                    Surprising Strings Time Limit:1000MS     Memory Limit:65536KB     64 ...

  5. 【字符串题目】poj 3096 Surprising Strings

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6193   Accepted: 403 ...

  6. Surprising Strings

    Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Description ...

  7. [ACM] POJ 3096 Surprising Strings (map使用)

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5783   Accepted: 379 ...

  8. POJ 3096:Surprising Strings

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6258   Accepted: 407 ...

  9. POJ3096:Surprising Strings(map)

    http://poj.org/problem?id=3096 for循环真是奇妙! #include <string.h> #include <stdio.h> #includ ...

随机推荐

  1. warning C4005: “AF_IPX”: 宏重定义的解决办法

    warning C4005: “AF_IPX”: 宏重定义warning C4005: “AF_IPX”: 宏重定义 解决方法: 由以上代码可以看出如果在没有定义WIN32_LEAN_AND_MEAN ...

  2. Javascript权威指南——第二章词法结构,第三章类型、值和变量,第四章表达式和运算符,第五章语句

    第二章 词法结构 一.HTML并不区分大小写(尽管XHTML区分大小写),而javascript区分大小写:在HTML中,这些标签和属性名可以使用大写也可以使用小写,而在javascript中必须小写 ...

  3. 10月14日下午MySQL数据库基础

    数据库基础 类型: 1.varchar:字符串,用于姓名班级,地址等,地址一般长50,姓名长20 2.int:整数,用于成绩,序号等 3.float:小数 4.bit:布尔型,用于性别等 5.时间也用 ...

  4. Java类集

    类集就是一个动态的对象数组,是对一些实现好的数据结构进行了包装,这样在使用时就会非常方便,最重要的是类集框架本身不受对象数组长度的限制. 类集框架的主要接口

  5. Bitmap动画

    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html htt ...

  6. csrf利用EXP

    <html><body><form action="http://www.xxx.com/user/setting/email_bind.html" ...

  7. Java中native关键字

    Java中native关键字 标签: Java 2016-08-17 11:44 54551人阅读 评论(0) 顶(23453) 收藏(33546)   今日在hibernate源代码中遇到了nati ...

  8. editplus如何配置php编译环境?

    为什么要配置php编译? 因为,要先看看 php文件是否能够 编译得过去, 有没有错误, 如果有错误, 不能通过编译, 则肯定不能运行. 所以, 可以先看一下编译 得不得行. 在preferences ...

  9. 优化 PHP 代码建议

    1.如果能将类的方法定义成static,就尽量定义成static,它的速度会提升将近4倍.2.$row[’id’] 的速度是$row[id]的7倍.3.echo 比 print 快,并且使用echo的 ...

  10. Linux下Redis常用命令

    >src/redis-server  启动 Redis 服务  或者>src/redis-server redis.conf src/redis-server redis.conf 1&g ...