2024牛客暑期多校训练营3 J-Rigged Games

链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网

题目描述

In a two-player competitive match, for any positive integer aaa, we define the Best of 2a−12a-12a−1 format as follows: the two players continue to compete until one of them wins aaa times, thereby winning the overall match. The Best of 2a−12a-12a−1 format includes a maximum of 2a−12a-12a−1 games and a minimum of aaa games.
 

For any two positive integers aaa and bbb, we define the Best of 2b−12b-12b−1 of Best of 2a−12a-12a−1 format as follows: the two players compete in a major match using the Best of 2b−12b-12b−1 format, which consists of a maximum of 2b−12b-12b−1 major games and a minimum of bbb major games. Each major game is a Best of 2a−12a-12a−1 format, consisting of a maximum of 2a−12a-12a−1 minor games and a minimum of aaa minor games. For example, Team A and Team B play a Best of 333 of Best of 555 match. Here are some possible outcomes (we use 111 to represent a win for Team A and 000 to represent a win for Team B):

  • 000111000 (Team A loses the first and third major games 0:3, wins the second major game 3:0, so the overall score is a 1:2 loss for Team A);
  • 0110000110 (Team A loses the first and second major games 2:3, so the overall score is a 0:2 loss for Team A).

Team A and Team B are currently engaged in a DotA2 match using the Best of 2b−12b-12b−1 of Best of 2a−12a-12a−1 format. To the spectators, this is an exciting event! However, unknown to the spectators, the entire match outcome is predetermined: there is a "script" of length nnn represented by a binary string TTT, where the results of the minor games will continuously repeat this pattern of 010101. Having this information, you want to know the match results when the "script" 010101 string is repeated from each position (see the sample explanation for details).

有道翻译如下:

在二人竞技比赛中,对于任意正整数a,我们定义2^(2a-1)的最佳形式如下:两名选手继续比赛,直到其中一人赢了一次,从而赢得了整场比赛。2^(2a-1)两局两胜制包括最多2^(2a-1)局和最少1局局。

对于任意两个正整数a和b,我们定义了Best of 2b - 1或Best of 2a - 1格式如下:两名选手使用Best of 2b - 1格式进行一场主要比赛,其中包括最多2b - 1场主要比赛和最少b场主要比赛。每场主要比赛是2胜1负的形式,包括最多2胜1负的小比赛和最少1胜2负的小比赛。例如,A队和B队进行五局三胜的比赛。以下是一些可能的结果(我们用1代表a队获胜,0代表B队获胜):

  • 000111000 (Team A loses the first and third major games 0:3, wins the second major game 3:0, so the overall score is a 1:2 loss for Team A);
  • 0110000110 (Team A loses the first and second major games 2:3, so the overall score is a 0:2 loss for Team A).

A队和B队目前正在进行一场DotA2比赛,他们采用的是2b - 1的形式。对于观众来说,这是一场激动人心的比赛!然而,观众不知道的是,整个比赛的结果是预先确定的:有一个长度为n的“脚本”,用二进制字符串T表示,其中小局的结果将不断重复这种01的模式。有了这些信息,您想知道在每个位置重复“script”01字符串时的匹配结果(有关详细信息,请参阅示例解释)。

题目大意

两队打比赛,大分 Bo2b − 1,小分 Bo2a − 1。 给定的长度为 n的串,两队比赛的每个小分结果是这个串的循环重复。 问从该串的每个位置开始,最终谁会赢得整个比赛。

题解 :

首先对每个位置,求出从它开始进行 Bo2a − 1后的胜负,以及比赛结束 时在循环串的位置。 上述可以用倍增,f(i, j)表示从位置 i开始进行 2 j局小分后的状态(两队 分别赢了几分,以及结束时在循环串的位置)。 处理完每一局从每个位置开始的结果后,再用倍增求每一大局的结果, 即用 g(i, j)表示从位置 i开始进行了 2 j小局后的状态(两队分别赢了几 分,以及结束时在循环串的位置)。

倍增:

用倍增来预处理2^1,2^2,2^3……结束时team A获胜的次数;

题目数据到2^8,但是保险起见还是开到2^18;

for(ll j=1;j<=18;j++){ 
		for(ll i=1;i<=n;i++){
			net[i][j]=net[net[i][j-1]][j-1];
			dq[i][j]=dq[i][j-1]+dq[net[i][j-1]][j-1];
		}	
	}

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define IOS std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll n,a,b,m;
string s;
const ll N=1e5+5;
ll pre[N*3];
ll dq[N][20],net[N][20];
int main(){
	IOS
	cin>>n>>a>>b;
	m=n;
	cin>>s;
	ll p=0,qa=0,qb=0;
	for(ll i=1;i<=n;i++){
		while(qa<a&&qb<a){
			if(s[p%n]=='1'){
				qa++;
			}else{
				qb++;
			}
			p++;
		}
		if(qa==a){
			dq[i][0]=1;
		}else{
			dq[i][0]=0;
		}
		net[i][0]=p%n+1;
		if(s[i-1]=='1'){
			qa--;
		}else{
			qb--;
		}
	}
	
	for(ll j=1;j<=18;j++){
		for(ll i=1;i<=n;i++){
			net[i][j]=net[net[i][j-1]][j-1];
			dq[i][j]=dq[i][j-1]+dq[net[i][j-1]][j-1];
		}	
	}
	for(ll i=1;i<=n;i++){
		ll x=i;
		ll num1=0;
		ll num=0;
		for(ll k=18;k>=0;k--){
			while(num+(1<<k)<=2*b-1){
				num+=(1<<k);
				num1+=dq[x][k];
				x=net[x][k];
			}
		}
		if(num1>=b){
			cout<<1;
		}else{
			cout<<0;
		}
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值