#include <bits/stdc++.h> typedef long long ll; const int maxx = 100010; const int inf = 0x3f3f3f3f; using namespace std; int main() { int n, m; cin >> n >> m; cout << (1 << n) * (m + 1) << endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; const int maxx = 100010; const int inf = 0x3f3f3f3f; using namespace std; int main() { ll a, b, n; cin >> a >> b >> n; cout << __gcd(a, b) << endl; return 0; }
思路: 这道题的话,每次操作可以将集合中的一个数字分解为它的任意两个非1的因数, 集合中的数字个数+1。因为质因数是无法再被分解的,所以最后集合中的数全为 n 的质因数。因此只需要看题目给定的n有多少个质因数。假设n有p个质因数,那么这场游戏将进行p-1次操作(每次操作后集合中的数字个数+1),如果p-1为奇数那么后手便无法再进行操作,如果p-1为偶数则先手再无法进行操作。所以我们只要筛一下素数就行了。最后$n==1$的情况要判断一下。
#include <bits/stdc++.h> typedef long long ll; const int maxx = 100010; const int inf = 0x3f3f3f3f; using namespace std; struct node { int s; int e; int v; } edge[maxx*5]; bool cmp(node a, node b) { return a.v < b.v; } int pre[maxx]; int n, m; void init() { for (int i = 0; i <= n; i++) pre[i] = i; } int getf(int a) { if (pre[a] == a) return a; int tmp = getf(pre[a]); return pre[a] = tmp; } int Kruskal(int a, int b) { int fa = getf(a); int fb = getf(b); if (fa != fb) { pre[fa] = fb; return 1; } else return 0; } int main() { while (cin >> n >> m) { init(); for (int i = 1; i <= m; i++) cin >> edge[i].s >> edge[i].e >> edge[i].v; sort(edge + 1, edge + m + 1, cmp); int ans = 0; for (int i = 1; i <= m; i++) { if (Kruskal(edge[i].s, edge[i].e)) ans += edge[i].v; } cout << ans << endl; } return 0; }
#include <algorithm> #include <iostream> #include <cstring> #include <climits> #include <cstdio> #include <vector> #include <cstdlib> #include <ctime> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #define fi first #define lc (x << 1) #define se second #define U unsigned #define rc (x << 1 | 1) #define Re register #define LL long long #define MP std::make_pair #define CLR(i, a) memset(i, a, sizeof(i)) #define FOR(i, a, b) for (Re int i = a; i <= b; ++i) #define ROF(i, a, b) for (Re int i = a; i >= b; --i) #define SFOR(i, a, b, c) for (Re int i = a; i <= b; i += c) #define SROF(i, a, b, c) for (Re int i = a; i >= b; i -= c) #define DEBUG(x) std::cerr << #x << '=' << x << std::endl const int MAXN = 1000000 + 5; int N, maxL; std::set<std::pair<int, int>> L; int a[MAXN]; inline int calc() { // 返回 set 中所有线段的并长度。(每个 pair 表示一个线段[first,second] int ans = 0; for (int i = 1; i <= maxL; i++) { if (a[i]) ans++; } return ans; } int main() { scanf("%d%d", &N, &maxL); while (N--) { int opt, x, y; scanf("%d%d%d", &opt, &x, &y); if (opt == 1) { if (L.find(MP(x, y)) != L.end()) continue; L.insert(MP(x, y)); for (int i = x; i <= y; i++) a[i]++; } if (opt == 2) { if (L.find(MP(x, y)) == L.end()) continue; L.erase(MP(x, y)); for (int i = x; i <= y; i++) a[i]--; } if (opt == 3) { printf("%d\n", calc()); } } return 0; }