AtCoder Beginning Contest 128
Posted jhseng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AtCoder Beginning Contest 128相关的知识,希望对你有一定的参考价值。
打完心情巨差,题目其实很简单,OJ垃圾。以后坚决不在这破OJ上用STL。
A:
一眼秒杀。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curPos<<1 15 #define rson curPos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 int a, p; 21 22 int main() { 23 cin >> a >> p; 24 cout << (a * 3 + p) / 2 << endl; 25 return 0; 26 }
B:
一眼秒杀。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curPos<<1 15 #define rson curPos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 struct Node { 21 string s; 22 int score, pos; 23 Node() {} 24 Node(string a, int b, int c) { 25 s = a; score = b; pos = c; 26 } 27 bool operator<(const Node &rhs)const { 28 if (s != rhs.s) return s < rhs.s; 29 else return score > rhs.score; 30 } 31 }; 32 33 vector<Node>v; 34 35 int main() { 36 int n; cin >> n; 37 rep1(i, 1, n) { 38 string s; int p; cin >> s >> p; 39 v.pb(s, p, i); 40 } 41 sort(v.begin(), v.end()); 42 for (auto i : v) cout << i.pos << endl; 43 return 0; 44 }
C:
一眼秒杀,枚举所有开关状态即可。但是用set T了超久都没发现导致极度自闭,比赛结束前十分钟重构改成数组就A了。垃圾OJ。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curPos<<1 15 #define rson curPos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 const int maxn = 15; 21 int n, m, p[maxn], ans = 0; 22 set<int>a[maxn]; //每个开关管哪些灯 23 24 int main() { 25 cin >> n >> m; 26 rep1(i, 1, m) { 27 int k; cin >> k; 28 while (k--) { 29 int x; cin >> x; 30 a[x].insert(i); 31 } 32 } 33 rep1(i, 1, m) cin >> p[i]; 34 int lim = pow(2, n); 35 int swit[maxn], time[maxn]; 36 for (int i = 0; i < lim; i++) { 37 int tmp = i, cnt = m, flag = 1; 38 for (int j = 0; j < maxn; j++) swit[j] = time[j] = 0; 39 while (tmp) swit[cnt--] = tmp % 2, tmp >>= 1; 40 for (int j = 1; j <= m; j++) 41 if (swit[j]) 42 for (auto p : a[j]) time[p]++; 43 for (int j = 1; j <= m; j++) 44 if (time[j] % 2 != p[j]) { 45 flag = 0; break; 46 } 47 if (flag) ans++; 48 } 49 cout << ans << endl; 50 return 0; 51 }
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curPos<<1 15 #define rson curPos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 const int maxn = 15; 21 int n, m, p[maxn], ans = 0, a[maxn][maxn]; 22 23 int main() { 24 scanf("%d%d", &n, &m); 25 rep1(i, 1, m) { 26 scanf("%d", &a[i][0]); 27 rep1(j, 1, a[i][0]) scanf("%d", &a[i][j]); 28 } 29 rep1(i, 1, m) scanf("%d", &p[i]); 30 rep1(i, 0, (1 << n) - 1) { 31 int flag = 1, cmp = i, swit[20], light[20], cnt = 0; 32 rep1(i, 1, 20) swit[i] = light[i] = 0; 33 while (cmp) swit[++cnt] = cmp & 1, cmp >>= 1; 34 rep1(i, 1, m) 35 rep1(j, 1, a[i][0]) light[i] += swit[a[i][j]]; 36 rep1(i, 1, m) if ((light[i] % 2) != p[i]) { 37 flag = 0; break; 38 } 39 if (flag) ans++; 40 } 41 printf("%d\n", ans); 42 return 0; 43 }
D:
一眼觉得是贪心,但是被上一题TLE搞到没心情想了。队友直接用了个O(n^3)的暴力枚举AC。先枚举答案由多少个数组成,再枚举从左边选的数的个数,最后枚举从右边选的数的个数。
正解也是枚举,但是如果这题数据量变大,能不能贪心呢?不太确定。
Code via. BWKPlus
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curPos<<1 15 #define rson curPos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 const int maxn = 60; 21 int a[maxn], now[maxn], ans = 0, n, m; 22 23 int main() { 24 scanf("%d%d", &n, &m); 25 rep1(i, 1, n) scanf("%d", &a[i]); 26 for (int i = 1; i <= min(n, m); i++) { 27 rep1(j, 0, i) { 28 rep1(k, 0, n) now[k] = 0; 29 int cnt = 0; 30 rep1(k, 1, i - j) now[++cnt] = a[k]; 31 rep1(k, 1, j) now[++cnt] = a[n - k + 1]; 32 sot(now, i); 33 int tot = m - i, sum = 0, x = 1; 34 while (tot && now[x] < 0) x++, tot--; 35 for (; x <= i; x++) sum += now[x]; 36 ans = max(ans, sum); 37 } 38 } 39 printf("%d\n", ans); 40 return 0; 41 }
E&&F:
待补。
以上是关于AtCoder Beginning Contest 128的主要内容,如果未能解决你的问题,请参考以下文章
Donation---AtCoder - AtCoder Regular Contest 098
AtCoder Beginner Contest 115 题解
AtCoder Beginner Contest 154 题解