本文主要是介绍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" "1–2" competes against the winner of the match " 3 – 4 " "3–4" "3–4"; the winner of the match " 5 – 6 " "5–6" "5–6" competes against the winner of the match " 7 – 8 " "7–8" "7–8", 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 2n−1
代码
#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;}
}
这篇关于A. Playoff的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!