10045 - Echo
Posted: Fri Dec 05, 2003 4:59 pm
Is there any tricks with this problem? It appears very straightforward but I keep on getting WA. I am solving this with a queue. Any help?
Thanks.
Thanks.
Code: Select all
47
a
ABBBBBBACCCCC
ABACADABACAD
ABACADAABACADA
ABBACC
ABBACC012345012345
ABACCB
ABACCB012345012345
ABACBC
ABACBC012345012345
A0123456789A
A012345678A
A0123456789
0123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678012345678AB
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678A
AB
ACABCB
ABCAB
aa0123456789b
ABACADAABACADA
aaabcdeaaabcde
ZaaabcdeaaaZbcde
aaaaaaaaabaaaaaaaaab
aaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaab
aaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaab
aaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaa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aaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaac
aaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaac
abcd
012345012345abba
abba012345012345
a
ab
aa
abc
aba
abb
bba
aaa
0123456789
01234567890
0123456789a
ACABCB
ABCAB
aa0123456789b
Code: Select all
Not an echo string, but still consistent with the theory
Not consistent with the theory
An echo string with buffer size ten
An echo string with buffer size ten
Not an echo string, but still consistent with the theory
Not consistent with the theory
Not an echo string, but still consistent with the theory
Not consistent with the theory
An echo string with buffer size ten
An echo string with buffer size ten
Not consistent with the theory
Not an echo string, but still consistent with the theory
Not consistent with the theory
Not an echo string, but still consistent with the theory
An echo string with buffer size ten
Not an echo string, but still consistent with the theory
Not consistent with the theory
Not an echo string, but still consistent with the theory
An echo string with buffer size ten
Not an echo string, but still consistent with the theory
Not consistent with the theory
An echo string with buffer size ten
An echo string with buffer size ten
Not consistent with the theory
An echo string with buffer size ten
An echo string with buffer size ten
An echo string with buffer size ten
An echo string with buffer size ten
Not consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
An echo string with buffer size ten
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not consistent with the theory
An echo string with buffer size ten
Not an echo string, but still consistent with the theory
Not consistent with the theory
Code: Select all
Not an echo string, but still consistent with the theory
Not consistent with the theory
An echo string with buffer size ten
An echo string with buffer size ten
Not an echo string, but still consistent with the theory
Not consistent with the theory
Not an echo string, but still consistent with the theory
Not consistent with the theory
An echo string with buffer size ten
An echo string with buffer size ten
Not consistent with the theory
Not an echo string, but still consistent with the theory
Not consistent with the theory
Not an echo string, but still consistent with the theory
An echo string with buffer size ten
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
An echo string with buffer size ten
Not an echo string, but still consistent with the theory
Not consistent with the theory
An echo string with buffer size ten
An echo string with buffer size ten
Not consistent with the theory
An echo string with buffer size ten
An echo string with buffer size ten
An echo string with buffer size ten
An echo string with buffer size ten
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
An echo string with buffer size ten
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not consistent with the theory
An echo string with buffer size ten
Not an echo string, but still consistent with the theory
Not consistent with the theory
Code: Select all
2
aaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaac
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678A
Code: Select all
Not consistent with the theory
Not consistent with the theory
Code: Select all
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Code: Select all
2
aaaaaaaaabaaaaaaaaac
0123456789012345678A
Code: Select all
Not consistent with the theory
Not consistent with the theory
Code: Select all
aaaaaaaaabaaaaaaaaac
Code: Select all
3
aaaaaaaaabaaaaaaaaac
aaaaaaaaabaaaaaaaaacdefghijk
aaaaaaaaabaaaaaaaaacdefghijkl
Code: Select all
Not an echo string, but still consistent with the theory
Not an echo string, but still consistent with the theory
Not consistent with the theory
Code: Select all
#include<iostream>
#include<string>
using namespace std;
int len,flag[1010],key[3],one;
char echo[1010];
/*
check whether I have already found the answer.
key[0]=1 means:found nothing
key[1]=1&&one means:
string is "Not an echo string, but still consistent with the theory"
key[2]=1 means:the string must be "echo"
*/
void chk()
{
int i,bound=len-1,cnt=10;
while(bound && cnt)
if(!flag[bound])
bound--,cnt--;
else if(flag[bound]==1)
break;
else
bound--;
for(i=0;i<=bound;i++)
if(!flag[i])
{
key[0]=1;
return ;
}
for(;i<len;i++)
if(!flag[i])
{
key[1]=1;
return ;
}
key[2]=1;
}
/*
have to stop my DFS function while I have already found the answer?
*/
bool dfs(char c,int start,int end)
{
if(end >= len)
{
chk();
if(key[2] || (one && key[1]))
return true;
return false;
}
int bound=start,cnt=10;
while(bound<len && cnt)
if(flag[bound])
bound++;
else
bound++,cnt--;
for(int i=end;i<len && i<=bound;i++)
if(!flag[i] && echo[i] == c)
{
flag[start]=1;
flag[i]=2;
int p=start;
while(p<len && flag[p])
p++;
if(key[2] || (one && key[1]) || dfs(echo[p],p,(p>=i)?p+1:i) )
return true;
flag[start]=flag[i]=0;
}
chk();
return false;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("10045.txt","w",stdout);
int dataset;
cin>>dataset;getchar();
while(dataset--)
{
gets(echo);
len=strlen(echo);
char buf[256];
int i;
memset(buf,0,sizeof(buf));
for(i=0;i<len;i++)
buf[echo[i]]++;
one=0;
for(i=0;i<256;i++)
if(buf[i]%2)
{
one=1;
break;
}
if(len<=10 && one)
{
cout<<"Not an echo string, but still consistent with the theory"<<endl;
continue;
}
memset(flag,0,sizeof(flag));
key[0]=key[1]=key[2]=0;
dfs(echo[0],0,1);
if(key[2])
cout<<"An echo string with buffer size ten"<<endl;
else if(key[1])
cout<<"Not an echo string, but still consistent with the theory"<<endl;
else
cout<<"Not consistent with the theory"<<endl;
}
return 0;
}