标签:icpc ace tor false nbsp code first ret --
A(题解看注释)
#include <bits/stdc++.h> #define P pair<int, int> using namespace std; struct mp { int p[7][7]; bool friend operator <(const mp &a, const mp &b) { for (int i =1 ; i <= 6; ++i) for (int j = 1; j <= 6; ++j) if (a.p[i][j] != b.p[i][j]) return a.p[i][j] < b.p[i][j]; return false; } }; struct node { P a[11], b[11]; // a【i】表示第i辆车的车头坐标,b【i】车尾 int cnt; mp p; }c; int n, ans = -1; int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; // 方向 set<mp> st; //剪枝 queue<node> q; bool move(node &res, int id, int de) { P &a = res.a[id], &b = res.b[id]; mp &p = res.p; if (a.first == b.first && de > 1) return false; //移动不合法 if (a.second == b.second && de < 2) return false; a.first += d[de][0], a.second += d[de][1]; if (a.first < 1 || a.first > 6 || a.second < 1|| a.second > 6) return false; if (p.p[a.first][a.second] != id && p.p[a.first][a.second] != 0) return false; b.first += d[de][0], b.second += d[de][1]; if (b.first < 1 || b.first > 6 || b.second < 1|| b.second > 6) return false; if (p.p[b.first][b.second] != id && p.p[b.first][b.second] != 0) return false; if (de == 0 || de == 2) p.p[a.first - d[de][0]][a.second - d[de][1]] = 0, p.p[b.first][b.second] = id; else if (de == 1 || de == 3) p.p[b.first - d[de][0]][b.second - d[de][1]] = 0, p.p[a.first][a.second] = id; return true; } int main() { for (int i = 1; i <= 6; ++i) for (int j = 1; j <= 6; ++j) { int m; cin >> m; //以后尽量用cin if (!m) continue; if (c.a[m].first == 0) c.a[m] = {i, j}; else c.b[m] = {i, j}; n = max(n, m); // 有几辆车 c.p.p[i][j] = m; } st.insert(c.p), q.push(c); while (!q.empty()) { c = q.front(); q.pop(); if (c.a[1] == make_pair(3, 5) && c.b[1] == make_pair(3, 6)) { ans = c.cnt + 2; break;} if (c.cnt >= 8) continue; //剪枝 for (int i = 1; i <= n; ++i) for (int j = 0; j < 4; ++j) //方向 { node res = c; ++res.cnt; if (move(res, i, j)) if (st.count(res.p)) continue; else st.insert(res.p), q.push(res); } } printf("%d", ans); return 0; }
C
#include <bits/stdc++.h> using namespace std; int n, a[55], flag; int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if (i != j) for (int k = j + 1; k <= n; ++k) if (i != k) if ((a[k] - a[j]) % a[i]) flag = 1; if (flag) puts("no"); else puts("yes"); return 0; }
D
#include <bits/stdc++.h> using namespace std; char a[10] = "bubble", b[10] = "tapioka", s[10000000]; int main() { int flag = 1; while (cin >> s) if (strcmp(a, s) && strcmp(b, s)) cout << s << ‘ ‘, flag = 0; if (flag) cout << "nothing"; return 0; }
E
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6; int t, k, len, n; int a[2000]; int main() { cin >>t; a[1] = -1; while (t--) { cin >> k >> len; n = 2; if (len >= 2000) {puts("-1"); continue;} int sum = max((k - 1) / maxn + 3, len); k = k + sum; for (int &i = n; i <= len || k > 0; ++i) if (k >= 1e6) a[i] = 1e6, k -= 1e6; else if (k > 0) a[i] = k, k = 0; else a[i] = 0; cout << n - 1 << ‘\n‘; for (int i = 1; i < n; ++i) cout << a[i] << ‘ ‘; puts(""); } return 0; }
H
#include <bits/stdc++.h> #define ll long long using namespace std; int t, n; int main() { cin >> t; while (t--) { cin >> n; cout << ((ll)n * (n + 1) ^ (n + 1)) << ‘\n‘; } return 0; }
J
#include <bits/stdc++.h> using namespace std; int s[505], t, n, m, mp[16][505], v[505], ans; vector<int> ve[505]; bool cmp(int a, int b) { return ve[a].size() < ve[b].size(); } void dfs(int k, int tot) { while (k <= n && v[s[k]]) ++k; if (k > n) { ans = min(ans, tot); return; } if (tot + 1 >= ans) return; for (int i = 0; i < ve[s[k]].size(); ++i) { int& id = ve[s[k]][i]; for (int j = 1; j <= n; ++j) v[j] += mp[id][j]; dfs(k + 1, tot + 1); for (int j = 1; j <= n; ++j) v[j] -= mp[id][j]; } } int main() { scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); ans = m; for (int i = 1; i <= n; ++i) vector<int>().swap(ve[i]), v[i] = 0, s[i] = i; for (int i = 1; i <= m; ++i) for (int j = 1; j <= n; ++j) { char c = getchar(); while (c != ‘0‘ && c != ‘1‘) c = getchar(); if (c == ‘1‘) mp[i][j] = 1, ve[j].emplace_back(i); else mp[i][j] = 0; } sort(s + 1, s + 1 + n, cmp); if (ve[s[1]].empty()) { puts("-1"); continue; } dfs(1, 0); printf("%d\n", ans); } return 0; }
K
#include <bits/stdc++.h> using namespace std; int t, n, a; priority_queue<int, vector<int>, greater<int> > q; int main() { cin >> t; while (t--) { cin >> n; while (n--) cin >> a, q.push(a); int ans = 0; while (!q.empty()) { int a = q.top(), b; q.pop(); if (!q.empty()) b = q.top(), q.pop(); else break; ans += a + b, q.push(a + b); } cout << ans << ‘\n‘; } return 0; }
ICPC Asia Taipei-Hsinchu Regional 2019
标签:icpc ace tor false nbsp code first ret --
原文地址:https://www.cnblogs.com/2aptx4869/p/12621024.html