[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;
}

转载于:https://www.cnblogs.com/xiao-ju-ruo-xjr/p/6105568.html

[POJ3096]Surprising Strings相关推荐

  1. POJ3096.Surprising Strings题解--zhengjun

    思路 一看这个字符串长度很小,就直接暴力就好了. 然后我们需要一种快速的查看是否有一对大写字符相同的容器. 于是就可以想到用 26 26 26 进制+桶,这样就是一一对应了. 代码 #include& ...

  2. POJ-3096(Surprising Strings)

    题目:Surprising Strings Description The D-pairs of a string of letters are the ordered pairs of letter ...

  3. sicily 1390 Surprising Strings

    这道题其实也不是很难,只是有些小细节需要注意而已,刚开始想着用C++的string类型,后来想到都是取出字符中的两个字符而已,就想到了用数组了,嘿嘿... // source code of subm ...

  4. POJ 3096 Surprising Strings

    这个题是对STL中Map的使用考察. 记录一下代码: #include <stdio.h> #include <map> #include <string.h> # ...

  5. idea直连linux部署项目,idea项目打包和在linux的部署

    浅谈:深入理解struts2的流程已经spring和struts2的整合 第一步:在tomcat启动的时候 1.在tomcat启动的时候,首先会加载struts2的核心过滤器StrutsPrepare ...

  6. POJ3096Surprising Strings(map)

    题意:输入很多字符串,以星号结束.判断每个字符串是不是"Surprising Strings",判断方法是:以"ZGBG"为例,"0-pairs&qu ...

  7. HOJ题目分类//放这儿没事刷刷学算法!嘻嘻!

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  8. 算法刷题记录(Day 12)

    Surprising Strings(poj 3096) 原题链接 解题思路:对于每一个D-pair的D值,生成相应的组,并存放在set中,若发现重复,则直接退出,否则代表成功. #include&l ...

  9. Chapter 3. Strings, Vectors and Arrays -C++ Primer 5 notes

    Chapter 3. Strings, Vectors and Arrays What does built-in types include? chapter 2 array maybe more? ...

最新文章

  1. Web Office 常见问题解决方法
  2. 上接[翻译]ASP.NET 2.0中的健康监测系统(Health Monitoring)(1) - 基本应用
  3. 深入理解Android中View
  4. 网络标准之:IANA定义的传输编码
  5. 存钱吃利息存邮政储蓄好还是农业银行好?
  6. Apache JMeter--网站自动测试与性能测评
  7. mysql 默认时间字段 1067,mysql替datetime类型字段设置默认值default
  8. 『收藏向 期末SSM课设救急』 教你从搭建到测试运行手撸一个SSM项目实战,附带源码,前端页面、解析和一般遇到的问题(排雷)
  9. Excel和PPT已经落后了,可视化大屏强在哪?一次看过瘾
  10. html5游戏 dice掷骰子,使用jQuery实现掷骰子游戏
  11. linux几个不常用但是很有用的命令
  12. matlab中投影,MATLAB在极射赤平投影中的应用
  13. 伟大的RAC和MVVM入门(二)
  14. 【渝粤教育】国家开放大学2018年秋季 7389-22T劳动与社会保障法 参考试题
  15. 应用案例 | 从Storm到Flink,有赞五年实时计算效率提升实践
  16. win10 安装 framework3.5
  17. Atititi 版本管理 rc final rtm ga release 软件的生命周期中一般分4个版本
  18. resin设置权限_resin加固
  19. 事件委托的灵活运用真不会求指教
  20. apk文件以及打包流程

热门文章

  1. 通过德雷福斯模型探寻成长之路
  2. Linux操作Oracle(8)——Oracle数据库迁移全纪录(1) — 表空间 用户 权限迁移
  3. Linux操作Oracle(12)——Oracle创建只读账号 【手把手教程】
  4. Ubuntu如何安装deb包 使用 dpkg解决依赖性问题
  5. vnpy学习_04回测评价指标的缺陷
  6. linux blind函数,C++拾遗--bind函数绑定
  7. php删除提示信息,php删除一条记录(删除确认提示)
  8. html地图动画效果图,【html】绚丽的HTML5地图分布动画DEMO演示
  9. python中inspect的用法(这个难懂,后期再补)
  10. mysql优化笔记,MySQL优化笔记