A. Playoff

A Playoff

原题地址
Consider a playoff tournament where 2 n 2^n 2n athletes compete. The athletes are numbered from 1 1 1 to 2 n 2^n 2n.

The tournament is held in n n n stages. In each stage, the athletes are split into pairs in such a way that each athlete belongs exactly to one pair. In each pair, the athletes compete against each other, and exactly one of them wins. The winner of each pair advances to the next stage, the athlete who was defeated gets eliminated from the tournament.
The pairs are formed as follows:

  • in the first stage, athlete 1 1 1 competes against athlete 2 ; 3 2; 3 2;3 competes against 4 ; 5 4; 5 4;5 competes against 6 6 6, and so on;
  • in the second stage, the winner of the match " 1 – 2 " "1–2" "12" competes against the winner of the match " 3 – 4 " "3–4" "34"; the winner of the match " 5 – 6 " "5–6" "56" competes against the winner of the match " 7 – 8 " "7–8" "78", and so on;
  • the next stages are held according to the same rules.

When athletes x x x and y y y compete, the winner is decided as follows:

  • if x + y x+y x+y is odd, the athlete with the lower index wins (i. e. if x < y x<y x<y, then x x x wins, otherwise y y y wins);
  • if x + y x+y x+y is even, the athlete with the higher index wins.

The following picture describes the way the tournament with n = 3 n=3 n=3 goes.
在这里插入图片描述
在这里插入图片描述

解题思路

游戏规则是 x + y x+y x+y是奇数时小的获胜是偶数时大的获胜,第一轮比赛是两个相邻的数比,两个相邻的数加起来就是奇数,所以所有的奇数获胜,所有奇数比较时加起来都是偶数,总共有 2 n 2^n 2n个数所以最后赢的是 2 n − 1 2^n-1 2n1

代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int sum=1<<n;
		cout<<sum-1<<endl;
		
	}
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值