题解:P13996 【MX-X19-T5】「FeOI Round 4.5」天使のクローバー
Water__Problem
·
·
题解
题解
直接做显然不太行,先打个表。
\texttt{01}
\texttt{0111}
\texttt{0111000111}
\texttt{0111000111010111000111}
\texttt{011100011101011100011101110111000111010111000111}
从第四段开始出现了规律。
~~场上我咋发现的来着?~~
然后我们发现这字符串长度增长的很快且当 $x$ 大的时候这个字符串前缀是不变的。
所以只用看第一个包含 $r$ 的字符串然后暴力找就行了。
## 代码
```cpp
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
void init();void solve();
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int T=1;init();
cin>>T;
while(T--) solve();
return 0;
}
void init(){
}
int x,r,cnt[1000],i;
int dfs(int i,int x){
if(i==-1) return 0;
if(i==0) return 1;
if(i==1) return 1;
if(x<=cnt[i-1]) return dfs(i-1,x);
x-=cnt[i-1];
if(x==1) return 0;
x--;
if(x<=cnt[max(i-3,0ll)]) return dfs(i-3,x);
x-=cnt[max(i-3,0ll)];
if(x==1) return 0;
x--;
return dfs(i-1,x);
}
void solve(){
cin>>x>>r;
if(r==0){
cout<<0<<endl;
return;
}
cnt[0]=1;
cnt[1]=3;
for(i=2;i<=x;i++){
cnt[i]=cnt[i-1]+1+cnt[max(i-3,0ll)]+1+cnt[i-1];
if(cnt[i]>=r) break;
}
if(i>x){
if(cnt[x]<r){
cout<<-1<<endl;
return;
}
i--;
}
cout<<dfs(i,r)<<endl;
}
```
代码里有些跟题解不一样是因为把每个字符串第一个 $0$ 去掉了。思路差不多。