TOJ 2522 水~ Surprising Strings

题目来源: http://acm.tju.edu.cn/toj/showp.php?pid=2522

看了半天题意== ,还在网上搜了才知道意思==

大致意思如下:

D pairs 是指 字符串中相邻为D的字母对, D-Unique 是指所有的Dpair 各不相同;即可;

比如 ZGBG ,  其中相邻为0  有: ZG , GB ,     BG 各不同,所以是0-unique; 距离为1的有, ZB, GG 不同所以为1-unique; 相邻为2只有ZG 也是2-Unique; 

用hash 或者map 映射一下,就可以;当然也可以暴力搜索;

下面是map 和hash 的代码:

#include 
#include 
#include 
using namespace std;
int DPair(string str)
{
    for(int D=0;D mymap;
        string ss="AA";
       for(int i=0;i>str)
    {
        i
        f(!str.compare("*")) break;
        if(DPair(str))
        cout<
hash 代码如下:
#include 
#include 
using namespace std;
int hash[2500];
int main()
{
    char str[85];
    while(cin>>str)
    {
        if(!strcmp(str,"*")) break;
        int d=0,len=strlen(str),flag=1;
        while(d




你可能感兴趣的:(TOJ)