Codeforces Round #412 Div.2

A.模拟

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 
 5 inline void read(int &ans) {
 6     static char ch = getchar();
 7     register int neg = 1;
 8     ans = 0;
 9     for (; !isdigit(ch); ch = getchar())
10         if (ch == '-') neg = -1;
11     for (; isdigit(ch); ch = getchar())
12         ans = ans * 10 + ch - '0';
13     ans *= neg;
14 }
15 
16 const int N = 1001;
17 int a[N], b[N], n;
18 
19 int main() {
20     read(n); bool flag = false;
21     for (int i = 0; i < n; ++i) {
22         read(a[i]), read(b[i]);
23         if (a[i] != b[i]) {
24             flag = true;
25             break;
26         }
27     }
28     if (flag) {
29         puts("rated"); return 0;
30     }
31     for (int i = 0; i < n; ++i) {
32         for (int j = i + 1; j < n; ++j) {
33             if (a[i] < a[j]) {
34                 flag = true;
35                 break;
36             }
37         }
38     }
39     if (flag)
40         puts("unrated");
41     else
42         puts("maybe");
43     return 0;
44 }
View Code

 

B.搜索

 1 #include<cstdio>
 2 #include<set>
 3 #include<queue>
 4 #include<vector>
 5 #include<iostream>
 6 using namespace std;
 7 
 8 inline void read(int &ans) {
 9     static char ch = getchar();
10     register int neg = 1;
11     ans = 0;
12     for (; !isdigit(ch); ch = getchar())
13         if (ch == '-') neg = -1;
14     for (; isdigit(ch); ch = getchar())
15         ans = ans * 10 + ch - '0';
16     ans *= neg;
17 }
18 
19 inline void get(int s, set < int > &si) {
20     int i = (s / 50) % 475;
21     for (int j = 0; j < 25; ++j) {
22         i = (i * 96 + 42) % 475;
23         si.insert(i + 26);
24     }
25 }
26 
27 int p, x, y, ans = ~0U >> 2;
28 set < int > ss[30000];
29 struct Node {
30     int s, m;
31     inline bool operator< (const Node &rhs) const {
32         return s < rhs.s;
33     }
34 };
35 set < Node > e;
36 
37 inline void bfs() {
38     queue < Node > q;
39     q.push((Node) {x, 0});
40     while (!q.empty()) {
41         Node c = q.front(); q.pop();
42         if (c.s < y || c.m >= ans) continue;
43         if (ss[c.s].empty()) get(c.s, ss[c.s]);
44         if (ss[c.s].count(p)) {
45             ans = min(ans, c.m);
46             continue;
47         }
48         q.push((Node) {c.s - 50, c.m});
49     }
50 
51     if (!ans) return;
52     while (!q.empty()) q.pop();
53     q.push((Node) {x, 0});
54 
55     while (!q.empty()) {
56         Node c = q.front(); q.pop();
57         if (c.s < y || c.m >= ans) continue;
58         e.insert(c);
59         if (ss[c.s].empty()) get(c.s, ss[c.s]);
60         if (ss[c.s].count(p)) {
61             ans = min(ans, c.m);
62             return;
63         }
64         if (!e.count((Node) {c.s + 100, c.m + 1})) q.push((Node) {c.s + 100, c.m + 1});
65         if (!e.count((Node) {c.s + 50, c.m + 1})) q.push((Node) {c.s + 50, c.m + 1});
66     }
67 }
68 
69 
70 int main() {
71     read(p); read(x); read(y);
72     bfs();
73     printf("%d\n", ans);
74     return 0;
75 }
View Code

 

CDE 太弱了,不会。

 

--------upd--------2017.5.14----------------------------------

 

C.可以推出一个式子, 注意p==0,p==q时要特判

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 4 using namespace std;
 5 
 6 inline void work() {
 7     int x, y, p, q;
 8     scanf("%d %d %d %d", &x, &y, &p, &q);
 9     if (p == 0) {
10         puts(x == 0 ? "0" : "-1"); return;
11     }
12     if (p == q) {
13         puts(x == y ? "0" : "-1"); return;
14     }
15     int t1 = (x + p - 1) / p;
16     int t2 = (y - x + q - p - 1) / (q - p);
17     cout << (q * 1LL * max(t1, t2) - y) << endl;
18 }
19 
20 int main() {
21     int T;
22     scanf("%d", &T);
23     while (T--) work();
24     return 0;
25 }
View Code

求 ceil(a/b) 可以这样搞 (a+b-1)/b

 

B.为什么我之前写的这么复杂。。。

显然分数只能50,50地增加或减少,让s从y开始一直增加,如果 s % 50 == x  % 50 则证明当前s是合法的(可以从x得到)。

如果s是可行的,那么s有3种情况。

1. s < x 输出0

2. s > x 且 (s - x) % 100 == 0 那么需要刚好(s - x) / 100次成功的hack

3. s  > x 且 (s - x) % 100 != 0 此时需要(s - x + 50) / 100次成功的hack

 这三种情况都可以归结到一个式子上 max(0, (s - x) + 50) / 100

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 4 using namespace std;
 5 
 6 int main() {
 7     int p, x, y;
 8     scanf("%d %d %d", &p, &x, &y);
 9     for (int s = y;; ++s) {
10         if (s % 50 != x % 50) continue;
11         bool flag = false;
12         int i = (s / 50) % 475;
13         for (int j = 0; j < 25; ++j) {
14             i = (i * 96 + 42) % 475;
15             if (i + 26 == p) {
16                 flag = true; break;
17             }
18         }
19         if (flag) {
20             printf("%d\n", (max(0, s - x) + 50) / 100); break;
21         }
22     }
23     return 0;
24 }
View Code

 

posted @ 2017-05-08 02:21  p0ny  阅读(120)  评论(0)    收藏  举报