#define ll long long #define N 1010 char s[N]; int a[8]; vector <string> res;
stringf(int x){ string res = ""; if (!x) return"0"; while (x) { int y = x % 16; if (y < 10) res += y + '0'; elseif (y == 10) res += 'a'; elseif (y == 11) res += 'b'; elseif (y == 12) res += 'c'; elseif (y == 13) res += 'd'; elseif (y == 14) res += 'e'; else res += 'f'; x /= 16; } reverse(res.begin(), res.end()); return res; }
intmain(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin >> T; for (int kase = 1; kase <= T; ++kase) { cout << "Case #" << kase << ": "; cin >> (s + 1); int len = 128; for (int i = 1; i <= len; i += 16) { int num = 0; for (int j = i; j < i + 16; ++j) { num = num * 2 + s[j] - '0'; } a[i / 16] = num; } res.clear(); string str = f(a[0]); for (int i = 1; i < 8; ++i) { str += ":"; str += f(a[i]); } res.push_back(str); string tmp = ""; for (int i = 0; i < 8; ++i) { string now = tmp; now += ":"; int j = i; for (; j < 8; ++j) { if (a[j]) break; } for (int k = j; k < 8; ++k) { now += ":"; now += f(a[k]); } if (j >= 8) now += ":"; if (j > i + 1) res.push_back(now); if (i) tmp += ":"; tmp += f(a[i]); } sort(res.begin(), res.end(), [](string x, string y){ if (x.length() != y.length()) return x.length() < y.length(); return x < y; }); cout << res[0] << "\n"; } return0; }
#define N 1010 #define INF 0x3f3f3f3f int n, k, a[N];
intcheck(int x){ int sum = 0; int box = 0; multiset <int> se; for (int i = 1; i <= n; ++i) { se.insert(a[i]); sum += a[i]; } for (int i = 1; i <= k; ++i) { int remind = x; while (!se.empty()) { auto pos = se.upper_bound(remind); if (pos != se.begin()) { --pos; remind -= (*pos); sum -= (*pos); se.erase(pos); } else { break; } } box += remind; if (se.empty()) return -INF; } return sum - box; }
intmain(){ int T; scanf("%d", &T); for (int kase = 1; kase <= T; ++kase) { printf("Case #%d: ", kase); scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", a + i); for (int i = 1; ; ) { int x = check(i); if (x == -INF) { printf("%d\n", i); break; } else { i += max(1, x / k + (x % k != 0)); } } } return0; }
intgetDay(int year, int month){ if (month == 2) { return days[2] + isLeap(year); } else { return days[month]; } }
intweek(int y, int m, int d){ int ans; if (m == 1 || m == 2) m += 12, y--; if ((y < 1752) || (y == 1752 && m < 9) || (y == 1752 && m == 9 && d < 3)) { ans = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 + 5) % 7; } else { ans = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7; } ans = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7; return ans + 1; }
boolcheck(int idx){ int y = 0, m = 0, d = 0; for (int i = 0; i < 4; i++) y = y * 10 + a[s[idx][i] - 'A']; for (int i = 5; i < 7; i++) m = m * 10 + a[s[idx][i] - 'A']; for (int i = 8; i < 10; i++) d = d * 10 + a[s[idx][i] - 'A']; if (y < 1600) returnfalse; if (m < 1 || m > 12) returnfalse; if (d < 1 || d > getDay(y, m)) returnfalse; return week(y, m, d) == 5; }
voidsolve(){ sort(s + 1, s + 1 + n); n = unique(s + 1, s + 1 + n) - s - 1; shuffle(s + 1, s + 1 + n, std::mt19937(std::random_device()())); for (int i = 0; i < 10; ++i) { a[i] = i; } do { bool flag = true; for (int i = 1; i <= n; ++i) { if (!check(i)) { flag = false; break; } } if (flag) { for (int i : a) { cout << i; } cout << "\n"; return; } } while (next_permutation(a, a + 10)); cout << "Impossible\n"; }
intmain(){ // freopen("input.txt", "r", stdin); ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int T; cin >> T; for (int cas = 1; cas <= T; ++cas) { cout << "Case #" << cas << ": "; cin >> n; for (int i = 1; i <= n; ++i) { cin >> s[i]; } solve(); } return0; }