inlinevoidchmax(int &a, int b){ if (b > a) a = b; }
inlineintrd(){ int s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * w; }
intmain(){ int t = rd(); while (t--) { memset(dp, 0xcf, sizeof(dp)); dp[0] = 0; int d = rd(); int m = rd(); dp[m] = 0; for (int i = 1; i <= d; ++i) { for (int j = 1; j <= 4; ++j) { v[i][j] = rd(); w[i][j] = rd(); } } for (int i = 1; i <= d; ++i) { for (int j = m; j >= 0; --j) { for (int k = 1; k <= 4; ++k) { if (j >= v[i][k]) { chmax(dp[j], dp[j - v[i][k] ] + w[i][k]); } } } } int ans = 0; for (int i = 0; i <= m; ++i) chmax(ans, dp[i]); printf("Budget #%d: Maximum of %d lives saved.\n", ++cas, ans); puts(""); } return0; }
int cnt, head[1010]; structedge {int v, next; } e[maxn << 1]; voidadd(int u, int v){ e[++cnt] = {v, head[u]}; head[u] = cnt; e[++cnt] = {u, head[v]}; head[v] = cnt; }
int n, m, tot; int vis[1010]; int ans[1010]; int deg[1010];
voiddfs(int u, int fa){ vis[u] = tot; for (int i = head[u]; i; i = e[i].next) { int v = e[i].v; if (v == fa) continue; if (vis[v]) { ans[tot] = 1; continue; } dfs(v, u); } }
voidrun(){ cnt = tot = 0; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) deg[i] = ans[i] = vis[i] = head[i] = 0; for (int i = 1, u, v; i <= m; ++i) { scanf("%d%d", &u, &v); add(u, v); deg[u] = deg[v] = 1; } for (int i = 1; i <= n; ++i) { if (!vis[i] && deg[i]) { ++tot; dfs(i, 0); } } int sum = 0; for (int i = 1; i <= tot; ++i) sum += ans[i]; printf("%d constellations, of which %d need to be fixed. \n", tot, sum); }
intmain(){ int _; scanf("%d", &_); for (int i = 1; i <= _; ++i) { if (i > 1) puts(""); printf("Night sky #%d: ", i); run(); } return0; }
voidrun(){ double a, p; scanf("%lf%lf", &a, &p); if(a == 1) { puts("Chester can do it!"); return ; } printf("%s\n", p * 0.2 < a * 0.5 ? "Chester will fail!" : "Chester can do it!"); }
intmain(){ int _; scanf("%d", &_); for (int i = 1; i <= _; ++i) { if (i > 1) puts(""); printf("Circus Act %d:\n", i); run(); } return0; }
constint maxn = 2e5 + 10; constint inf = 0x3f3f3f3f; int n, m, k; bool ok[21]; int sta[21]; int a, b; char s[3]; int tot; int cas;
intmain(){ while (~scanf("%d %d %d", &n, &m, &k), n | k | m) { tot = (1 << k) - 1; // printf("%d\n", tot); for (int i = 1; i <= n; ++i) { scanf("%d", &a); sta[i] = 0; while (a--) { scanf("%d", &b); sta[i] |= (1 << (b - 1)); } scanf("%s", s); if (s[0] == 'Y') ok[i] = true; else ok[i] = false; } int t = sta[m]; bool good = ok[m]; int ans = inf; for (int i = m; i >= 1; --i) { t |= sta[i]; good |= ok[i]; // printf("%d %d\n", t, good); int step = (m - i) * 2; int to = t; bool g = good; if (g && to == tot) ans = min(ans, step); for (int j = m + 1; j <= n; ++j) { to |= sta[j]; g |= ok[j]; step += 2; if (g && to == tot) { ans = min(ans, step); break; } } } printf("Test case #%d: ", ++cas); if (ans < inf) printf("%d\n", ans); elseputs("Impossible"); puts(""); } return0; }
vector<int> gao(char a[]){ vector<int> ans; int len = strlen(a); for (int i = 0; i < len; ++i) { int x = (a[i] >= '0' && a[i] <= '9') ? x = a[i] - '0' : x = a[i] - 'a' + 10; ans.push_back((x / 8) & 1); ans.push_back((x / 4) & 1); ans.push_back((x / 2) & 1); ans.push_back(x & 1); } return ans; }
vector<int> sol(vector<int> a, vector<int> b){ int c1 = 0, c2 = 0; while (a[c1] == 0) ++c1; while (b[c2] == 0) ++c2; vector<int> ans; for (; c1 < a.size() && c2 < b.size(); ++c1, ++c2) { if (a[c1] == b[c2]) ans.push_back(a[c1]); elsereturn ans; } return ans; }
voidprint(vector<int> a){ int tem = 0; int k = a.size() % 4; for (int i = 0; i < k; ++i) tem = tem * 2 + a[i]; if (tem) printf("%c", cha[tem]); for (int i = k; i < a.size(); i += 4) { tem = 0; for (int j = i; j < i + 4; ++j) tem = tem * 2 + a[j]; printf("%c", cha[tem]); } printf("\n"); }