• [交互题] Codeforces 1282D Enchanted Artifact


    题目大意

    本题为交互题。有一个字符串s,只由字符'a'和'b'组成。每次你可以询问一个非空的字符串,它会返回这两个字符串的编辑距离。为一个字符串经过修改,删除或插入操作得到另一个字符串,两个字符串编辑距离的定义为最小的操作次数,若返回值为0,那么就是字符串s。让你在n + 2操作内得出字符串s(n为字符串s的长度,未知),且每次询问的字符串长度不得超过300。

    题解

    首先我们当然得去知道这个字符串有多长。
    第一次去询问("a"),设回答是(Len)。若(Len=300),显然答案是(300)(b),直接输出即可。否则,(++Len),再去询问(Len)(a),设回答为(CountB),若(CountB=0),则已经找到了。若(CountB=Len),则说明答案是(Len-1)(b)。否则(Len)就是答案字符串的长度,且(CountB)就是答案字符串中(b)的个数。我们依次去询问(Len-1)("baa...aa")("aba...aa")("aab...aa")(...)(aaa...ba),即可知道每个位置上是否是b,因为我们已经知道(b)的个数,所以只需询问(Len-1)次即可判断最后一位是否是(b),加上开始时用了2步,最后给出答案还需1步,总共用了(Len+2)步,满足要求。

    Code

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    using namespace std;
    
    #define RG register int
    #define LL long long
    
    int CountB=0,Dis,Len;
    
    int main(){
        ios::sync_with_stdio(false);
        cout<<"a"<<endl;
        cin>>Len;++Len;
        if(Len>300){
            for(RG i=1;i<Len;++i)
                cout<<'b';
            cout<<endl;
            int x;cin>>x;
            return 0;
        }
        string S(Len,'a');
        string Ans(Len,'a');
        cout<<S<<endl;
        cin>>CountB;
        if(CountB==0) return 0;
        if(CountB==Len){
            for(RG i=1;i<Len;++i)
                cout<<'b';
            cout<<endl;
            int x;cin>>x;
            return 0;
        }
        int Count=0;
        for(RG i=0;i<Len-1;++i){
            S[i]='b';cout<<S<<endl;
            int x;cin>>x;
            if(x<CountB){Ans[i]='b';++Count;}
            S[i]='a';
        }
        if(Count<CountB) Ans[Len-1]='b';
        cout<<Ans<<endl;
        int x;cin>>x;
        return 0;
    }
    
  • 相关阅读:
    常见http状态码
    通过adb shell命令查看内存,CPU,启动时间,电量等信息
    Jmeter获取数据库数据参数化
    jmeter链接mysql数据库,sql数据库,oracle数据库
    appium 隐藏键盘
    python编码
    python:打印所有文件名字的扩展名
    python中字符串常见操作
    python中的字符串存储及切片介绍
    Ubuntu14.04安装部署bugzilla5.0.3
  • 原文地址:https://www.cnblogs.com/AEMShana/p/12340854.html
Copyright © 2020-2023  润新知