#include <bits/stdc++.h> using namespace std; using LL = long long; int k, n; int x; signed main() { // freopen("in", "r", stdin); // freopen("out", "w", stdout); while (~scanf("%d%d", &k, &n)) { int cur = 0, cnt = 0; int ok = 0; for (int i = 1; i <= n; i++) { scanf("%d", &x); if (ok) continue; if (cur + x == k) { if(n != i) ok = 1; cur += x; } else if (cur + x > k) { cnt++; cur = k - (cur + x - k); } else { cur += x; } } if (ok || k == 0) { printf("paradox "); } else { printf("%d %d ", k - cur, cnt); } } return 0; }
#include <bits/stdc++.h> using namespace std; using LL = long long; #define A 1 #define B 2 #define C 3 #define D 4 #define E 5 #define F 6 const int maxn = 1010; int n; int dice[maxn][7]; int pre[maxn]; int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); } void unite(int x, int y) { x = find(x); y = find(y); pre[x] = y; } int check(int x, int y) { if (dice[x][1]==dice[y][A]&&dice[x][2]==dice[y][B]&&dice[x][3]==dice[y][C]&&dice[x][4]==dice[y][D]&&dice[x][5]==dice[y][E]&&dice[x][6]==dice[y][F]) return 1; if (dice[x][1]==dice[y][C]&&dice[x][2]==dice[y][D]&&dice[x][3]==dice[y][B]&&dice[x][4]==dice[y][A]&&dice[x][5]==dice[y][E]&&dice[x][6]==dice[y][F]) return 1; if (dice[x][1]==dice[y][B]&&dice[x][2]==dice[y][A]&&dice[x][3]==dice[y][D]&&dice[x][4]==dice[y][C]&&dice[x][5]==dice[y][E]&&dice[x][6]==dice[y][F]) return 1; if (dice[x][1]==dice[y][D]&&dice[x][2]==dice[y][C]&&dice[x][3]==dice[y][A]&&dice[x][4]==dice[y][B]&&dice[x][5]==dice[y][E]&&dice[x][6]==dice[y][F]) return 1; if (dice[x][1]==dice[y][A]&&dice[x][2]==dice[y][B]&&dice[x][3]==dice[y][D]&&dice[x][4]==dice[y][C]&&dice[x][5]==dice[y][F]&&dice[x][6]==dice[y][E]) return 1; if (dice[x][1]==dice[y][C]&&dice[x][2]==dice[y][D]&&dice[x][3]==dice[y][A]&&dice[x][4]==dice[y][B]&&dice[x][5]==dice[y][F]&&dice[x][6]==dice[y][E]) return 1; if (dice[x][1]==dice[y][B]&&dice[x][2]==dice[y][A]&&dice[x][3]==dice[y][C]&&dice[x][4]==dice[y][D]&&dice[x][5]==dice[y][F]&&dice[x][6]==dice[y][E]) return 1; if (dice[x][1]==dice[y][D]&&dice[x][2]==dice[y][C]&&dice[x][3]==dice[y][B]&&dice[x][4]==dice[y][A]&&dice[x][5]==dice[y][F]&&dice[x][6]==dice[y][E]) return 1; if (dice[x][1]==dice[y][A]&&dice[x][2]==dice[y][B]&&dice[x][3]==dice[y][F]&&dice[x][4]==dice[y][E]&&dice[x][5]==dice[y][C]&&dice[x][6]==dice[y][D]) return 1; if (dice[x][1]==dice[y][F]&&dice[x][2]==dice[y][E]&&dice[x][3]==dice[y][B]&&dice[x][4]==dice[y][A]&&dice[x][5]==dice[y][C]&&dice[x][6]==dice[y][D]) return 1; if (dice[x][1]==dice[y][B]&&dice[x][2]==dice[y][A]&&dice[x][3]==dice[y][E]&&dice[x][4]==dice[y][F]&&dice[x][5]==dice[y][C]&&dice[x][6]==dice[y][D]) return 1; if (dice[x][1]==dice[y][E]&&dice[x][2]==dice[y][F]&&dice[x][3]==dice[y][A]&&dice[x][4]==dice[y][B]&&dice[x][5]==dice[y][C]&&dice[x][6]==dice[y][D]) return 1; if (dice[x][1]==dice[y][A]&&dice[x][2]==dice[y][B]&&dice[x][3]==dice[y][E]&&dice[x][4]==dice[y][F]&&dice[x][5]==dice[y][D]&&dice[x][6]==dice[y][C]) return 1; if (dice[x][1]==dice[y][E]&&dice[x][2]==dice[y][F]&&dice[x][3]==dice[y][B]&&dice[x][4]==dice[y][A]&&dice[x][5]==dice[y][D]&&dice[x][6]==dice[y][C]) return 1; if (dice[x][1]==dice[y][B]&&dice[x][2]==dice[y][A]&&dice[x][3]==dice[y][F]&&dice[x][4]==dice[y][E]&&dice[x][5]==dice[y][D]&&dice[x][6]==dice[y][C]) return 1; if (dice[x][1]==dice[y][F]&&dice[x][2]==dice[y][E]&&dice[x][3]==dice[y][A]&&dice[x][4]==dice[y][B]&&dice[x][5]==dice[y][D]&&dice[x][6]==dice[y][C]) return 1; if (dice[x][1]==dice[y][F]&&dice[x][2]==dice[y][E]&&dice[x][3]==dice[y][C]&&dice[x][4]==dice[y][D]&&dice[x][5]==dice[y][A]&&dice[x][6]==dice[y][B]) return 1; if (dice[x][1]==dice[y][C]&&dice[x][2]==dice[y][D]&&dice[x][3]==dice[y][E]&&dice[x][4]==dice[y][F]&&dice[x][5]==dice[y][A]&&dice[x][6]==dice[y][B]) return 1; if (dice[x][1]==dice[y][E]&&dice[x][2]==dice[y][F]&&dice[x][3]==dice[y][D]&&dice[x][4]==dice[y][C]&&dice[x][5]==dice[y][A]&&dice[x][6]==dice[y][B]) return 1; if (dice[x][1]==dice[y][D]&&dice[x][2]==dice[y][C]&&dice[x][3]==dice[y][F]&&dice[x][4]==dice[y][E]&&dice[x][5]==dice[y][A]&&dice[x][6]==dice[y][B]) return 1; if (dice[x][1]==dice[y][E]&&dice[x][2]==dice[y][F]&&dice[x][3]==dice[y][C]&&dice[x][4]==dice[y][D]&&dice[x][5]==dice[y][B]&&dice[x][6]==dice[y][A]) return 1; if (dice[x][1]==dice[y][D]&&dice[x][2]==dice[y][C]&&dice[x][3]==dice[y][E]&&dice[x][4]==dice[y][F]&&dice[x][5]==dice[y][B]&&dice[x][6]==dice[y][A]) return 1; if (dice[x][1]==dice[y][F]&&dice[x][2]==dice[y][E]&&dice[x][3]==dice[y][D]&&dice[x][4]==dice[y][C]&&dice[x][5]==dice[y][B]&&dice[x][6]==dice[y][A]) return 1; if (dice[x][1]==dice[y][C]&&dice[x][2]==dice[y][D]&&dice[x][3]==dice[y][F]&&dice[x][4]==dice[y][E]&&dice[x][5]==dice[y][B]&&dice[x][6]==dice[y][A]) return 1; return 0; } signed main() { // freopen("in", "r", stdin); // freopen("out", "w", stdout); while (~scanf("%d", &n)) { for (int i = 1; i <= n; i++) { pre[i] = i; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= 6; j++) { scanf("%d", &dice[i][j]); } } for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (check(i, j)) unite(i, j); } } int ret1 = 0; for (int i = 1; i <= n; i++) { if (i == find(i)) ret1++; } printf("%d ", ret1); map<int, int> vis; for (int i = 1; i <= n; i++) { vis[find(i)]++; } vector<int> ret2; for (const auto &x : vis) { ret2.emplace_back(x.second); } sort(ret2.begin(), ret2.end(), greater<int>()); for (int i = 0; i < ret2.size(); i++) { printf("%d%c", ret2[i], " "[i == ret2.size() - 1]); } } return 0; } 贴一下枚举的图吧。。
#include <bits/stdc++.h> using namespace std; using LL = long long; using pii = pair<int, int>; const int maxn = ; int n, m, t; pii lunch[maxn], dinner[maxn]; int suf[maxn]; signed main() { // freopen("in", "r", stdin); // freopen("out", "w", stdout); while (~scanf("%d%d%d",&n,&m,&t)) { for (int i = 1; i <= n; i++) { scanf("%d%d",&lunch[i].second, &lunch[i].first); } for (int i = 1; i <= m; i++) { scanf("%d%d",&dinner[i].second, &dinner[i].first); } if (t == 0) { printf("0 "); continue; } sort(lunch + 1, lunch + n + 1); sort(dinner + 1, dinner + m + 1); int ret = INT_MAX; for (int i = 1; i <= n; i++) { if (lunch[i].first >= t) ret = min(ret, lunch[i].second); } for (int i = 1; i <= m; i++) { if (dinner[i].first >= t) ret = min(ret, dinner[i].second); suf[i] = dinner[i].second; } for (int i = m - 1; i >= 1; i--) { suf[i] = min(suf[i + 1], suf[i]); } for (int i = 1; i <= n; i++) { if (lunch[i].first >= t) continue; int require = t - lunch[i].first; if (dinner[m].first < require) continue; int lo = 1, hi = m; while (lo <= hi) { int mid = (lo + hi) >> 1; if (dinner[mid].first >= require) { ret = min(ret, suf[mid] + lunch[i].second); hi = mid - 1; } else { lo = mid + 1; } } } printf("%d ", ret == INT_MAX ? -1 : ret); } return 0; }
#include <bits/stdc++.h> using namespace std; using LL = long long; using pii = pair<int, int>; const LL mod = 1E9 + 9; const int dx[5] = {0, 0, 1, -1}; const int dy[5] = {1, -1, 0, 0}; const int maxn = 7; char s[maxn][maxn]; vector<pii> pos; int n = 6, m = 6; LL ret; vector<vector<int>> status; vector<int> tmp; void pre(int cnt, int cap) { if (cnt == min((int)pos.size() + 1, 7)) { status.emplace_back(tmp); return; } for (int i = 1; i <= 6; i++) { // if (i == cap) continue; tmp.emplace_back(i); pre(cnt + 1, i); tmp.pop_back(); } } int check(int x, int y) { return x >= 1 && x <= 6 && y >= 1 && y <= 6; } int ok() { for (int i = 1; i <= 6; i++) { for (int j = 1; j <= 6; j++) { for (int k = 0; k < 4; k++) { int x = i + dx[k]; int y = j + dy[k]; if (!check(x, y)) continue; if (s[i][j] == '*') continue; if (s[x][y] == s[i][j]) return 0; } } } return 1; } signed main() { // freopen("in", "r", stdin); // freopen("out", "w", stdout); pos.clear(); for (int i = 1; i <= 6; i++) { scanf("%s", s[i] + 1); for (int j = 1; j <= 6; j++) { if (s[i][j] == '#') pos.emplace_back(i, j); } } tmp.clear(); status.clear(); pre(1, -1); for (int i = 0; i < status.size(); i++) { for (int j = 0; j < pos.size(); j++) { int x = pos[j].first, y = pos[j].second; s[x][y] = status[i][j] + '0'; } if (ok()) { ret++; if (ret >= mod) ret %= mod; } for (int j = 0; j < pos.size(); j++) { int x = pos[j].first, y = pos[j].second; s[x][y] = '#'; } } printf("%lld ", ret); return 0; } 没得100分,确定不来啃啃[阿里云-超全算法笔试模拟题精解合集]? [阿里云-超全算法笔试模拟题精解合集]--70+算法题、30种大厂笔试高频知识点
版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/qkl-jc/33456.html