题意:
思路:
首先我们发现如果知道了字符串的长度,我们就可以
O
(
n
+
1
)
O(n+1)
O(n+1)次询问求解出来。比如当前长度为
n
n
n,那么我们就可以构造出一个长度为
n
n
n的全
′
a
′
'a'
′a′字符串,让后问一下他的花费
c
o
s
t
cost
cost,之后遍历每一位,把它修改成
′
b
′
'b'
′b′,看花费是否减少,如果不能减少就改回
′
a
′
'a'
′a′,否则的话就更新花费。
既然如此我们考虑如何
1
1
1次询问求出长度。
首先它可以插入,修改,删除。修改求长度不是很现实,我们考虑插入和删除。
首先可以询问一下
′
a
′
'a'
′a′这个字符,返回值为
x
x
x。现在无非几种情况:
(
1
)
(1)
(1)要求的串就是
′
a
′
'a'
′a′,返回
0
0
0,直接结束。
(
2
)
(2)
(2)要求的串全是
′
b
′
'b'
′b′,那么这个串长度必须是
x
x
x,因为这
x
x
x个修改里面有一次是把
′
a
′
'a'
′a′改成
′
b
′
'b'
′b′的,剩下的都是插入
′
b
′
'b'
′b′。
(
3
)
(3)
(3)要求的串有至少一个
′
a
′
'a'
′a′,那么这个串长度是
x
+
1
x+1
x+1,因为有一个
′
a
′
'a'
′a′,还需要插入
x
x
x个数。
当然直接按照以上思路来的话次数是
O
(
n
+
3
)
O(n+3)
O(n+3)的,因为我们要询问
x
x
x个
′
b
′
'b'
′b′的花费,还要询问
x
+
1
x+1
x+1个
′
a
′
'a'
′a′的花费,所以我们考虑是否能利用已经询问过的信息来解决。
考虑如果
x
x
x个
′
b
′
'b'
′b′不符合的话,假设他的返回值为
y
y
y,那么我们知道符合条件的长度是
x
+
1
x+1
x+1,那么我们需要把
y
−
−
y--
y−−来增加一个长度,之后的
y
y
y就是初始状态全为
′
b
′
'b'
′b′的花费了,我们可以把之前询问全
′
a
′
'a'
′a′的操作去掉,因为全
′
a
′
'a'
′a′和全
′
b
′
'b'
′b′是一样的,这样次数就是
O
(
n
+
2
)
O(n+2)
O(n+2)了。
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;
//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;
int x,y;
string s;
int a[1000];
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
s="a";
cout<<s<<endl; cout.flush();
cin>>x;
string ans;
for(int i=1;i<=x;i++) ans+='b';
cout<<ans<<endl; cout.flush();
cin>>y;
y--; s="";
for(int i=1;i<=x+1;i++) s+='b';
int mi=INF;
for(int i=0;i<s.length();i++)
{
s[i]='a'; int now;
cout<<s<<endl; cout.flush();
cin>>now;
if(now>y) s[i]='b';
else y=now;
}
return 0;
}
/*
*/