zoukankan      html  css  js  c++  java
  • POJ 3096 Surprising Strings

    Surprising Strings

    Time Limit: 1000ms
    Memory Limit: 65536KB
    This problem will be judged on PKU. Original ID: 3096
    64-bit integer IO format: %lld      Java class name: Main
     
     

    The <dfn>D-pairs of a string of letters are the ordered pairs of letters that are distance D from each other. A string is <dfn>D-unique if all of its D-pairs are different. A string is <dfn>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.

     

    Input

    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.

     

    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

     
    解题:直接暴力了,利用map!其实set也可以。题意就是找出距离为k的两个字符组成的串。在k的距离下,有两个或者多个串一样。那么不surprising了。
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <climits>
     7 #include <vector>
     8 #include <queue>
     9 #include <cstdlib>
    10 #include <string>
    11 #include <set>
    12 #include <map>
    13 #include <stack>
    14 #define LL long long
    15 #define pii pair<int,int>
    16 #define INF 0x3f3f3f3f
    17 using namespace std;
    18 map<string,int>mp;
    19 char str[100],tmp[5];
    20 int main() {
    21     while(~scanf("%s",str)){
    22         if(str[0] == '*') break;
    23         int len = strlen(str);
    24         bool flag = true;
    25         for(int k = 1; k < len; k++){
    26             mp.clear();
    27             for(int j = 0; j+k < len; j++){
    28                 tmp[0] = str[j];
    29                 tmp[1] = str[j+k];
    30                 tmp[2] = '';
    31                 if(mp[tmp]) {flag = false;break;}
    32                 mp[tmp]++;
    33             }
    34             if(!flag) break;
    35         }
    36         if(flag) printf("%s is surprising.
    ",str);
    37         else printf("%s is NOT surprising.
    ",str);
    38     }
    39     return 0;
    40 }
    View Code
  • 相关阅读:
    Oracle ——优化内存
    用 C# 实现 HTTP 协议多线程下载文件
    Oracle 为表某个字段进行字母数字组合编码
    Oracle 11g Release 1 (11.1)——自动存储管理(Automatic Storage Management,ASM)
    Oracle 11g Release 1 (11.1) Oracle Text 如何创建 CTXCAT 索引
    Oracle ——如何确定性能差的 SQL
    MySQL 5.5/5.6——概述 MySQL 客户端程序
    Oracle 数据库统计信息描述
    Oracle Database Instant Client
    HTTP 协议演示——HTTP 协议(45)
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/3934358.html
Copyright © 2011-2022 走看看