2018-2019 ACM-ICPC Asia Jakarta Regional Contest
有个队友咕咕了,打得一般,题目难度不是很难
A:
solver:czq
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 string s; 15 16 int main() { 17 ios::sync_with_stdio(false); 18 cin.tie(0); 19 cin >> s; 20 int n = s.size(), zero = 0, one = 0; 21 for (auto i : s) { 22 if (i == '0') zero++; 23 else one++; 24 } 25 if (zero == one) { 26 if (s[0] == '0') { 27 cout << "1"; 28 for (int i = 0; i < n - 1; i++) cout << "0"; 29 } else { 30 cout << "0"; 31 for (int i = 0; i < n - 1; i++) cout << "1"; 32 } 33 cout << endl; 34 } else { 35 for (int i = 0; i < n; i++) { 36 if (zero > one) { 37 if (s[i] == '0') s[i] = '1'; 38 } else { 39 if (s[i] == '1') s[i] = '0'; 40 } 41 } 42 cout << s << endl; 43 } 44 return 0; 45 }
D:
solver:czq、zyh
一开始还看错题了,原来穿过的冰面是不算的,需要把地图中间的冰面换成草地
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 const int MAXN = 555; 15 int n, m, ans = 0; 16 char a[MAXN][MAXN]; 17 18 int main() { 19 scanf("%d%d", &n, &m); 20 for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1); 21 if (n == 1) { 22 for (int i = 2; i < m; i++) { 23 if (a[1][i] == '.') ans++; 24 } 25 printf("%d\n", ans); 26 } else if (n == 2) { 27 for (int i = 2; i < m; i++) { 28 if (a[1][i] == '.' && a[1][i] == a[2][i]) ans++; 29 } 30 printf("%d\n", ans); 31 } else if (m == 1) { 32 for (int i = 2; i < n; i++) { 33 if (a[i][1] == '.') ans++; 34 } 35 printf("%d\n", ans); 36 } else if (m == 2) { 37 for (int i = 2; i < n; i++) { 38 if (a[i][1] == '.' && a[i][1] == a[i][2]) ans++; 39 } 40 printf("%d\n", ans); 41 } else { 42 int tmp = 1; 43 for (int i = 1; i <= n; i++) { 44 for (int j = 1; j <= m; j++) { 45 if ((i == 1 || i == n) && (j == 1 || j == m)) continue; 46 else if (i == 1 || i == n || j == 1 || j == m) { 47 if (a[i][j] == '#') tmp = 0; 48 } else if (a[i][j] == '.') ans++; 49 } 50 } 51 printf("%d\n", ans + tmp); 52 } 53 return 0; 54 }
G:
solver:czq
挺弱智的图论题
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 const int MAXN = 555; 15 int n, m, d[MAXN], cnt = 0, ans = 999, vis[MAXN][MAXN]; 16 // since max d[x]+d[y] is 999 17 18 int main() { 19 ios::sync_with_stdio(false); 20 cin.tie(0); 21 cin >> n >> m; 22 cnt = n * (n - 1) / 2; 23 for (int i = 1; i <= m; i++) { 24 int s, t; cin >> s >> t; 25 d[s]++, d[t]++; 26 vis[s][t] = vis[t][s] = 1; 27 cnt--; 28 } 29 30 function<void(int, int)> solve = [&](int x, int y) { 31 if (x > y) swap(x, y); 32 d[x]++, d[y]++; 33 vis[x][y] = vis[y][x] = 1; 34 cnt--; 35 for (int i = 1; i <= n; i++) { 36 if (i == x || i == y) continue; 37 if (!vis[x][i] && d[x] + d[i] >= ans) solve(x, i); 38 if (!vis[y][i] && d[y] + d[i] >= ans) solve(y, i); 39 } 40 }; 41 42 while (cnt) { 43 ans--; 44 for (int i = 1; i <= n; i++) { 45 for (int j = i + 1; j <= n; j++) { 46 if (!vis[i][j] && d[i] + d[j] >= ans) { 47 solve(i, j); 48 } 49 } 50 } 51 } 52 53 printf("%d\n", ans); 54 return 0; 55 }
H:
solver:czq
优先队列
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 const int MAXN = 1e5 + 10; 15 struct Node { 16 int l, r, c; 17 Node() {} 18 Node(int _l, int _r, int _c): l(_l), r(_r), c(_c) {} 19 bool operator<(const Node &rhs)const { 20 return l < rhs.l || (l == rhs.l && r < rhs.r); 21 } 22 } que[MAXN]; 23 priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>pq; 24 int n, m, qTop = 0, s = 0, a[MAXN], pre[MAXN], cnt0[MAXN]; 25 26 int main() { 27 ios::sync_with_stdio(false); 28 cin.tie(0); 29 pre[0] = cnt0[0] = 0; 30 cin >> n >> m; 31 for (int i = 1; i <= n; i++) { 32 cin >> a[i]; 33 pre[i] = pre[i - 1] + a[i]; 34 cnt0[i] = cnt0[i - 1] + (a[i] == 0 ? 1 : 0); 35 } 36 int flag = 1; 37 for (int i = 0; i < m; i++) { 38 int l, r, c; 39 cin >> l >> r >> c; 40 int tmp = pre[r] - pre[l - 1] + cnt0[r] - cnt0[l - 1] - c; 41 if (tmp < 0) { 42 cout << "Impossible" << endl; 43 flag = 0; 44 } 45 que[i] = Node(l, r, tmp / 2); 46 } 47 if (!flag) return 0; 48 sort(que, que + m); 49 for (int i = 1; i <= n; i++) { 50 while (qTop < m && que[qTop].l <= i) { 51 pq.push(mp(que[qTop].c + s, que[qTop].r)); 52 qTop++; 53 } 54 while (pq.size() && pq.top().second < i) pq.pop(); 55 if (a[i]) continue; 56 if (pq.empty() || pq.top().first > s) { 57 s++, a[i] = -1; 58 } else { 59 a[i] = 1; 60 } 61 } 62 for (int i = 1; i <= n; i++) { 63 if (i > 1) cout << " "; 64 cout << a[i]; 65 } 66 cout << endl; 67 return 0; 68 }
I:
solver:czq
光速签到
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 const int MAXN = 1e5 + 10; 15 int n, ans = 0; 16 string s[MAXN]; 17 18 int main() { 19 ios::sync_with_stdio(false); 20 cin.tie(0); 21 cin >> n; 22 for (int i = 0; i < n; i++) cin >> s[i]; 23 ans = s[n - 1][0] == 'T' ? 1 : 0; 24 for (int i = n - 2; i >= 0; i--) { 25 if (s[i][0] == 'L') ans ^= 1; 26 } 27 if (ans) cout << "TRUTH" << endl; 28 else cout << "LIE" << endl; 29 return 0; 30 }
J:
solver:czq、zyh
dfs搞出所有字串之后O(n)dp
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 const int MAXN = 5e6 + 10, MAXM = 20; 15 struct Node { 16 char s[MAXM]; 17 int id; 18 bool operator<(const Node &rhs)const { 19 int t = strcmp(s, rhs.s); 20 return t ? t<0: id>rhs.id; 21 } 22 } a[MAXN]; 23 int n, aTop = 0, sum[MAXM]; 24 char s[MAXM], t[MAXM]; 25 26 int main() { 27 28 function<void(int, int, int)> dfs = [&](int step, int length, int id) { 29 if (!s[step]) { 30 if (length) { 31 copy(t, t + length, a[aTop].s); 32 a[aTop++].id = id; 33 } 34 return; 35 } 36 dfs(step + 1, length, id); 37 t[length] = s[step]; 38 dfs(step + 1, length + 1, id); 39 }; 40 41 scanf("%d", &n); 42 for (int i = 1; i <= n; i++) { 43 scanf("%s", s); 44 dfs(0, 0, i); 45 } 46 for (int i = 1; i <= n; i++) sum[i] = INT_MIN; 47 sort(a, a + aTop); 48 for (int i = 0; i < aTop; i++) { 49 sum[a[i].id] = max(sum[a[i].id], (int)strlen(a[i].s) + sum[a[i].id - 1]); 50 } 51 printf("%d\n", max(sum[n], -1)); 52 return 0; 53 }
L:
solver:zyh
1 #include <bits/stdc++.h> 2 using namespace std; 3 char str[100]; 4 long long p[61]; 5 long long mask[61]; 6 void init() { 7 p[0] = 1; 8 mask[0] = 1; 9 for (int i = 1; i < 61; ++i) { 10 p[i] = p[i - 1] * 2; 11 mask[i] = p[i] | mask[i - 1]; 12 } 13 } 14 long long findMaxBit(long long x) { 15 int cnt = 0; 16 for (int i = 60; i >= 1; --i) { 17 if (x & p[i]) cnt++; 18 if (cnt == 2) return ((x >> (i + 1)) << i) | (mask[i - 1] & x); 19 } 20 return x >> 1; 21 } 22 void output(long long x) { 23 if (x > 1) output(x >> 1); 24 cout << (x & 1); 25 } 26 int main() { 27 long long k, s = 0; 28 cin >> k; 29 cin >> str; 30 31 init(); 32 //cout<<p[60]<<endl<<mask[60]<<endl; 33 int len = strlen(str); 34 for (int i = len - 1; i >= 0; --i) { 35 if (str[i] == '1') s += p[len - i - 1]; 36 } 37 int ans = 0; 38 while (s > k) { 39 ans++; 40 s = findMaxBit(s); 41 //output(s); 42 //cout<<endl; 43 } 44 cout << ans; 45 }