跳到正文

题解

题解:P13996 【MX-X19-T5】「FeOI Round 4.5」天使のクローバー

Water__Problem约 3 分钟
原文
文章信息与版本

文章信息

发布
2025年9月8日
收录
2025年12月12日
更新
2026年11月9日
篇幅
约 3 分钟
获赞
4
题目
P13996

版本

  1. v2当前
  2. v1

题解

直接做显然不太行,先打个表。

01\texttt{01}

0111\texttt{0111}

0111000111\texttt{0111000111}

0111000111010111000111\texttt{0111000111010111000111}

011100011101011100011101110111000111010111000111\texttt{011100011101011100011101110111000111010111000111}

从第四段开始出现了规律。

si=si−1+si−3+si−1s_i=s_{i-1}+s_{i-3}+s_{i-1}。

场上我咋发现的来着?

然后我们发现这字符串长度增长的很快且当 xx 大的时候这个字符串前缀是不变的。

所以只用看第一个包含 rr 的字符串然后暴力找就行了。

代码

C++
#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;
}

代码里有些跟题解不一样是因为把每个字符串第一个 00 去掉了。思路差不多。

原文
存档评论1 条抓取于