int n; structLine { double k, b; booloperator< (const Line& t) const { if (k != t.k) return k < t.k; return b < t.b; } }l[N];
intmain() { for (int x1 = 0; x1 < 20; x1 ++ ) for (int y1 = 0; y1 < 21; y1 ++ ) for (int x2 = 0; x2 < 20; x2 ++ ) for (int y2 = 0; y2 < 21; y2 ++ ) if (x1 != x2) { double k = (double)(y2 - y1) / (x2 - x1); double b = y1 - k * x1; l[n ++ ] = {k, b}; }
sort(l, l + n); int res = 1; for (int i = 1; i < n; i ++ ) if (fabs(l[i].k - l[i - 1].k) > 1e-8 || fabs(l[i].b - l[i - 1].b) > 1e-8) res ++ ; cout << res + 20 << endl;
while (hh != tt) { int t = q[hh ++ ]; if (hh == N) hh = 0; st[t] = false;
for (int i = h[t]; i != -1; i = ne[i]) { int j = e[i]; if (dist[j] > dist[t] + w[i]) { dist[j] = dist[t] + w[i]; if (!st[j]) // 如果队列中已存在j,则不需要将j重复插入 { q[tt ++ ] = j; if (tt == N) tt = 0; st[j] = true; } } } } }
intmain() { n = 2021; memset(h, -1, sizeof h); for (int i = 1; i <= n; i ++ ) for (int j = max(1, i - 21); j <= min(n, i + 21); j ++ ) { int d = gcd(i, j); add(i, j, i * j / d); }
spfa(); printf("%d\n", dist[n]); return0; }
答案
1
10266837
F.时间显示
思路
先将毫秒转换成秒,然后求小时(86400=60*60*24)、分钟(3600=60*60)、秒
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<bits/stdc++.h>
usingnamespacestd;
typedeflonglong LL;
intmain() { LL n; cin >> n; n /= 1000; n %= 86400; int h = n / 3600; n %= 3600; int m = n / 60; int s = n % 60; printf("%02d:%02d:%02d\n", h, m, s); return0; }
LL C(int a, int b) { LL res = 1; for (int i = a, j = 1; j <= b; i --, j ++ ) { res = res * i / j; if (res > n) return res; } return res; }
boolcheck(int k) { LL l = k * 2, r = max((LL)n, l); while (l < r) { LL mid = l + r >> 1; if (C(mid, k) >= n) r = mid; else l = mid + 1; } if (C(r, k) != n) returnfalse;
cout << r * (r + 1) / 2 + k + 1 << endl;
returntrue; }
intmain() { cin >> n; for (int k = 16; ; k -- ) if (check(k)) break; return0; }