不定项选择题
思路
啊,咱就是说这个题目描述是多么通俗易懂啊。
我们可以知道,这道题是只有选或不选两种情况,就是问你有多少种情况,我们可以知道就是有 \(2^n\) 种情况,即 (1<<n)
种,但是题目中有一个情况不算,就是都不选的情况,所以我们最后要减 \(1\)。即 (1<<n)-1
,这就是最后的公式。
代码
/*
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define re register
#define swap(a, b) a ^= b, b ^= a, a ^= b
#define pb push_back
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef pair<int, int> PII;
const ll N = 1e6 + 10;
const ll M = 1e6 + 10;
const ll Max = 1e3 + 5;
const ll INF = 1e18, P = 998244353;
const double eps = 1e-6;
inline ll read() { ll x = 0; bool f = true; char c = getchar(); while (c < 48 || c > 57) { if (c == '-') f = false; c = getchar(); } while (c >= 48 && c <= 57) x = (x << 3) + (x << 1) + c - 48, c = getchar(); return f ? x : -x; }
inline void write(ll x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + 48); }
inline void wsp(int x) { write(x), putchar(' '); }
inline void wel(int x) { write(x), putchar('\n'); }
int n;
int main()
{ // freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
cout<<(1<<n)-1;
return 0;
}
标签:10,const,P9779,int,ll,2023,inline,HUSTFC,define
From: https://www.cnblogs.com/gongyuchen/p/17804753.html