Codeforces Round #467 (Div. 2)
A |
输出除0以外的数字种数即可。
B |
猜想答案离y不会很远。暴力枚举答案, $O(\sqrt n)$验证,如果有因数落在区间$[2,p]$里就不合法。
C |
二分答案搞一搞。
D |
如果走到一个出度为零而且该对面走的点p就赢了。如果有环就可以平局。否则就输了。
找到点p之后往回走走到起始点就行了,记录下这条路径。
E |
先坑着。
1 #include<cstdio> 2 #include<iostream> 3 #include<set> 4 using namespace std; 5 int main() { 6 set < int > s; 7 int n; scanf("%d", &n); 8 for (int i = 0, t; i < n; ++i) { 9 scanf("%d", &t); 10 if (t) s.insert(t); 11 } 12 cout << s.size(); 13 return 0; 14 }
1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 int p, y; 5 bool check(int x) { 6 for (int i = 1; i * i <= x; ++i) if (x % i == 0) { 7 if (i >= 2 && i <= p) return false; 8 if (x / i >= 2 && x / i <= p) return false; 9 } 10 return true; 11 } 12 int main() { 13 cin >> p >> y; 14 int ans = -1; 15 for (int i = y; i >= max(2, y - 2000); --i) { 16 if (check(i)) { 17 ans = i; break; 18 } 19 } 20 printf("%d\n", ans); 21 return 0; 22 }
1 #include<cstdio> 2 #include<cmath> 3 #include<iostream> 4 using namespace std; 5 typedef double db; 6 typedef long long ll; 7 ll k, d, t, T, x1, x2; 8 bool check(db x) { 9 ll p = (ll)x / T; 10 db a = x1 * p, b = x2 * p; 11 x -= p * T; 12 a += min(x, (db)x1); 13 x -= x1; 14 b += max(.0, x); 15 return a * 2 + b >= t * 2; 16 } 17 int main() { 18 cin >> k >> d >> t; 19 T = (k + d - 1) / d * d; 20 x1 = (k / d) * d + (k % d); 21 x2 = T - x1; 22 double l = 0, r = t * 2; 23 for (int i = 0; i < 1000; ++i) { 24 double m = (l + r) / 2; 25 if (check(m)) r = m; 26 else l = m; 27 } 28 printf("%.15lf\n", l); 29 return 0; 30 }
1 #include<queue> 2 #include<cstdio> 3 #include<vector> 4 #include<iostream> 5 #define pb push_back 6 #define mp make_pair 7 using namespace std; 8 const int N = 100005; 9 int n, m, vis[N][2], out[N], vs[N], son[N][2]; 10 vector < int > g[N], r[N]; 11 void dfs(int u, int d) { 12 vis[u][d] = 1; 13 for (int v, i = 0; i < g[u].size(); ++i) { 14 v = g[u][i]; 15 if (!vis[v][!d]) dfs(v, !d); 16 } 17 } 18 bool dfs(int u) { 19 if (vs[u]) return true; 20 vs[u] = 1; 21 for (int i = 0; i < g[u].size(); ++i) 22 if (dfs(g[u][i])) return true; 23 vs[u] = 0; 24 return false; 25 } 26 bool circle() { 27 return dfs(m); 28 } 29 int main() { 30 scanf("%d%d", &n, &m); 31 for (int c, i = 1; i <= n; ++i) { 32 scanf("%d", &c); out[i] = c; 33 for (int t; c--;) { 34 scanf("%d", &t); 35 g[i].pb(t); 36 r[t].pb(i); 37 } 38 } 39 scanf("%d", &m); 40 dfs(m, 0); 41 int p = 0; 42 for (int i = 1; i <= n; ++i) if (!out[i]) { 43 if (vis[i][1]) {p = i; break;} 44 } 45 if (p) { 46 queue < pair < int , int > > q; 47 q.push(mp(p, 1)); 48 while (!q.empty()) { 49 int u = q.front().first, s = q.front().second; q.pop(); 50 for (int i = 0; i < r[u].size(); ++i) { 51 int v = r[u][i]; 52 if (vis[v][!s] && !son[v][!s]) { 53 son[v][!s] = u; q.push(mp(v, !s)); 54 } 55 } 56 } 57 puts("Win"); 58 for (int u = m, s = 1; u; s ^= 1, u = son[u][s]) { 59 printf("%d ", u); 60 } printf("\n"); 61 } else { 62 if (circle()) puts("Draw"); 63 else puts("Lose"); 64 } 65 return 0; 66 }