跳到正文

题解

P9779 [HUSTFC 2023] 不定项选择题 tj

_colin1112_约 1 分钟
原文
文章信息与版本

文章信息

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

版本

  1. v1当前

思路

对于每一道题,有两种选择:勾选与取消勾选。

拓展到 nn 道题上,最坏的操作次数就是 2n2^n 次。

而每道选择题不能都不选,因此需要减去一个操作次数。

AC Code

第一种:

C++
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
const int E=1e6+5;
ll n;
int main(){
    IO;
    cin >>n;
    cout <<(1<<n)-1;
    return 0;
}

第二种:

C++
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
const int E=1e6+5;
ll n;
int main(){
    IO;
    cin >>n;
    ll ans=pow(2,n);
    cout <<ans-1;
    return 0;
}
原文