Codeforces Round #467 (Div. 2)

A

Olympiad

输出除0以外的数字种数即可。

B

Vile Grasshoppers

猜想答案离y不会很远。暴力枚举答案, $O(\sqrt n)$验证,如果有因数落在区间$[2,p]$里就不合法。

C

Save Energy!

二分答案搞一搞。

D

Sleepy Game

如果走到一个出度为零而且该对面走的点p就赢了。如果有环就可以平局。否则就输了。

找到点p之后往回走走到起始点就行了,记录下这条路径。

E

Lock Puzzle

先坑着。

 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 }

A

 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 }

B

 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 }

C

 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 }

D

原文地址:https://www.cnblogs.com/p0ny/p/8472467.html

时间: 2024-08-05 02:04:12

Codeforces Round #467 (Div. 2)的相关文章

Codeforces Round #467 (Div. 2) -----d

D. Sleepy Game 又是好几天之前的题目了,这几天一直沉迷于王者农药,今天总算把这道题写了. 考试的时候:看完题面,博弈论????emmm好像从出度为0的点倒着递推过来就行了?(从来没写过博弈论),可是平局怎么弄,,,行吧不写了(没时间了). 考完之后跟同学说这道题,他告诉我这不是个博弈问题....又去认认真真读了一遍样例,确实不是. 官方拖了好几天才发题解. 先看赢的情况,这不是一个博弈问题,后手要帮着先手赢的,所以其实就是找一条路径,从s开始,经过奇数条边,最终到达的点出度为0.那

Codeforces Round #467 (Div. 2) E -Lock Puzzle

Lock Puzzle 题目大意:给你两个字符串一个s,一个t,长度<=2000,要求你进行小于等于6100次的shift操作,将s变成t, shift(x)表示将字符串的最后x个字符翻转后放到最前面. 思路:不会写,看了题解... 因为长度为3000,操作为6500,我们考虑每三次操作将一个字符放到最后,并保证其他字符的顺序不变,这样是可以实现的, 如果我们想要将第k个字符移到最后,我们只要shift(n-1-k) , shift(1) , shift(n-1),就能实现啦 . 1 #incl

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除

Codeforces Round #339 (Div. 2) B. Gena&#39;s Code

B. Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, f

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un