跳到正文

题解

CF1767D Playoff 题解

OIerr约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
题目
CF1767D

版本

  1. v1当前

题目大意

读入 nn,代表有 2n2^n 个队伍参加比赛,每次相邻的两个队比赛,字符串中 0 表示分低的胜利,1 表示分高的胜利。

解题思路

对于 a<b<c<da<b<c<d:字符串是 01 或者 10,可以发现都只有 b,cb,c 可以赢得比赛,字符串中 01 的顺序对答案没有影响。

  • 1 的个数 xx:使得前 [1,2x)[1,2^x) 都会被淘汰掉;
  • 0 的个数 yy:使得后面 (2n−2y+1,2n](2^n-2^y+1,2^n] 都被淘汰掉;

最终留下 [2x,2n−2y+1][2^x,2^n - 2^y +1]。

AC 代码

C++
#include <bits/stdc++.h>
#define x first
#define int long long
#define y second
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<char,int> PCI;
typedef pair<LL,LL> PLL;
//typedef __int128 i128;
typedef unsigned long long ULL;
const int N=2e5+10,INF = 1e9 ,mod = 1e9 + 7 ,P = 131;
const double eps = 1e-7;
int p[N],q[N];
vector<int> pos[N];


int n;
void solve()
{
    string s;
    cin >> n >> s ;
    int k = count(s.begin(),s.end(),'1');

    for(int x = 1 << k ;x <= (1<<n) - (1<<(n-k)) + 1;x ++ )
    cout << x  << " ";
}
signed main()
{
//    freopen("1.txt","r",stdin);
    ios
    LL T=1;
//    cin>>T;
    while(T -- )
    {
        solve();
    }
    return 0;
}
原文