Codeforces Round #610 (Div. 2) D. Enchanted Artifact Interaction + Thinking

Portal

Article Directory

Title:

Insert picture description here

Ideas:

First of all, we found that if we know the length of the string, we can O (n + 1) O(n+1)O ( n+1 ) Solve the query in the second time. For example, the current length isnnn , then we can construct a length ofnnn full'a' 'a'a' String, let me ask about hiscost costc o s t , then traverse each bit and modify itto'b''b'b′ To see if the cost is reduced, if it cannot be reduced, change back to′ a ′'a'a , Otherwise update the cost.
In this case, we consider how to1 1Find the length in one query.
First of all, it can be inserted, modified, and deleted. Modifying the length is not very realistic, we consider inserting and deleting.
First you can ask about'a''a'a' This character, the return value isxxx . Now there are just a few situations:
(1) (1)( 1 ) The required stringis'a''a'a , return0 00 , end directly.
( twenty two)( 2 ) The required strings areall'b''b'b , Then the length of this string must bexxx because of thisxxOne of the x changes is tochange'a''a'a' Change' b '' b 'b' , the rest are insertedinto'b''b'b
( 3 ) (3) ( 3 ) The required string has at leastone'a''a'a , Then the length of this string isx + 1 x+1x+1 because there isan'a''a'a , also need to insertxxx number.
Of course, if you follow the above ideas directly, the number of times isO (n + 3) O(n+3)O ( n+3 ) because we want to askxxx a'b' 'b'b′’S cost, we also need to askx + 1 x+1x+. 1 th'a' 'a'a Cost, so we consider whether we can use the information that has been asked to solve it.
Consider ifxxx a'b' 'b'b′If not, suppose his return value isyyy , then we know that the qualified length isx + 1 x+1x+1 , then we need to puty − − y--and To increase a length, and thenyyy means that the initial state isall'b''b'b′’S cost, we can ask all′ a ′'a'a Operation is removed, because all′ a ′'a'a And all′ b ′'b'b Is the same, so the number of times isO (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;
}
/*

*/









Guess you like

Origin blog.csdn.net/m0_51068403/article/details/115295999