「杂题乱刷2」CF862D
1.「杂题乱刷」AT_abc020_c2.「杂题乱刷」CF1846E1 & CF1846E23.「杂题乱刷」CF786C4.「杂题乱刷」Zheng Rui 327 【2018普转提day17专题】洗5.「杂题乱刷」CF1759F6.「杂题乱刷」CF1979C7.「杂题乱刷」CF1985F8.「杂题乱刷」P13969.「杂题乱刷」AT_abc360_d10.「杂题乱刷2」CF1454F Array Partition11.「杂题乱刷2」CF1996F12.「杂题乱刷2」CF1486C1 & CF1486C213.「杂题乱刷2」CF1360H
14.「杂题乱刷2」CF862D
15.「杂题乱刷2」CF1301C16.「杂题乱刷2」CF2036G17.「杂题乱刷2」P1126718.「杂题乱刷2」CF1370F219.「杂题乱刷2」AT_abc140_e20.「杂题乱刷2」CF601B21.「杂题乱刷2」CF2069D22.「杂题乱刷2」P11830 [省选联考 2025] 幸运数字23.「杂题乱刷2」P11843 [USACO25FEB] The Best Subsequence G简单题。
题目链接
CF862D Mahmoud and Ehab and the binary string
解题思路
首先我们可以发现,字符串的第一个字母不是
然后,显然的,我们以先找到的数字为
的字符串的权值差为
综上,询问次数为
参考代码
点击查看代码
#include<bits/stdc++.h>
using namespace std;
//#define map unordered_map
#define re register
#define ll long long
#define forl(i,a,b) for(re ll i=a;i<=b;i++)
#define forr(i,a,b) for(re ll i=a;i>=b;i--)
#define mid ((l+r)>>1)
#define lowbit(x) (x&-x)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
//#define endl '\n'
#define QwQ return 0;
ll _t_;
void _clear(){}
ll n;
string ans;
string S;
ll get(string s)
{
ll sum=0;
forl(i,0,n-1)
sum+=s[i]!=ans[i];
return sum;
}
ll ask(string s)
{
cout<<"? "<<s<<endl;
ll x;//=get(s);
cin>>x;
return x;
}
string f(ll x)
{
string SS="";
forl(i,1,x)
SS+='0';
forl(i,x+1,n)
SS+='1';
return SS;
}
string f2(ll x)
{
string SS="";
forl(i,1,x)
SS+='1';
forl(i,x+1,n)
SS+='0';
return SS;
}
ll ans0,ans1;
void solve()
{
_clear();
cin>>n;
forl(i,1,n)
S+='0';
ll q1=ask(S);
S[0]='1';
ll q2=ask(S);
if(q1>q2)
ans1=1;
else
ans0=1;
S="";
forl(i,1,n)
S+='1';
ll q3=ask(S);
if(!ans0)
{
ll L=1,R=n;
while(L<R)
{
ll Mid=(L+R)/2;
if(ask(f(Mid))==q3+Mid)
L=Mid+1;
else
R=Mid;
}
cout<<"! "<<L<<' '<<ans1<<endl;
}
else
{
ll L=1,R=n;
while(L<R)
{
ll Mid=(L+R)/2;
if(ask(f2(Mid))==q1+Mid)
L=Mid+1;
else
R=Mid;
}
cout<<"! "<<ans0<<' '<<L<<endl;
}
}
int main()
{
// IOS;
_t_=1;
// cin>>_t_;
while(_t_--)
solve();
QwQ;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效