A. Playoff

2023-10-25 18:10
文章标签 playoff

本文主要是介绍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;}
}

这篇关于A. Playoff的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/284314

相关文章

CodeForces 1535D : Playoff Tournament 二叉树

传送门 题意 分析 模拟一颗二叉树,找到待修改的节点然后向上维护即可 代码 #pragma GCC optimize(3)#include <bits/stdc++.h>#define debug(x) cout<<#x<<":"<<x<<endl;#define dl(x) printf("%lld\n",x);#define di(x) printf("%d\n",x);

CF1767D Playoff(递推)

Playoff - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) Problem - D - Codeforces 读入n,代表有2^n个队伍参加比赛,每次相邻的两个队比赛,字符串中0->分低的胜利,1->分高的胜利路 对于a<b<c<d;字符串是01或者10,可以发现都只有b,c可以赢得比赛,字符串中01的顺序对答案没有影响 1的个数x->使得前[1,2^x)

F-Playoff题解

目录 题目描述: 题目分析: Ac代码: 原题链接 题目描述: Consider a playoff tournament where 2^n athletes compete. The athletes are numbered from 1 to 2^n. The tournament is held in n stages. In each stage, the athl

D. Playoff Tournament - 线段树 -建模

Problem - D - Codeforces D. Playoff Tournament time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output 2k2k teams participate in a playo