# 5/5

``` 1 /*zhen hao*/
2 #include <bits/stdc++.h>
3 using namespace std;
4
5 #define lson l, m, rt*2
6 #define rson m + 1, r, rt*2+1
7 #define xx first
8 #define yy second
9
10 typedef pair<int,int> pii;
11 typedef long long ll;
12 typedef unsigned long long ull;
13
14 int s[110], n;
15
16 int cal() {
17   int p1, m1 = 110, p2, m2 = -110;
18   for (int i = 1; i <= n; i++) {
19     if (m1 > s[i]) m1 = s[i], p1 = i;
20     if (m2 < s[i]) m2 = s[i], p2 = i;
21   }
22   int ret = abs(p1 - p2);
23   return ret;
24 }
25
26 int main() {
27 //  freopen("case.in", "r", stdin);
28   cin >> n;
29   for (int i = 1; i <= n; i++) cin >> s[i];
30   int ans = 0;
31   for (int i = 1; i <= n; i++)
32     for (int j = i + 1; j <= n; j++) {
33       swap(s[i], s[j]);
34       ans = max(ans, cal());
35       swap(s[i], s[j]);
36     }
37   printf("%d\n", ans);
38   return 0;
39 }```

``` 1 /*zhen hao*/
2 #include <bits/stdc++.h>
3 using namespace std;
4
5 #define lson l, m, rt*2
6 #define rson m + 1, r, rt*2+1
7 #define xx first
8 #define yy second
9
10 typedef pair<int,int> pii;
11 typedef long long ll;
12 typedef unsigned long long ull;
13
14 int n, t;
15 int v[110][2];
16 double cnt[1100];
17
18 void init() {
19   int cur = 1;
20   for (int i = 1; i < 11; i++) {
21     for (int j = 0; j < i; j++) {
22       v[cur][0] = cur + i;
23       v[cur][1] = cur + i + 1;
24 //      cout << cur << ‘ ‘ << v[cur][0] << ‘ ‘ << v[cur][1] << endl;
25       cur++;
26     }
27   }
28 }
29
30 void dfs(int d, int cur, double add) {
32   if (d >= n) return;
33   if (cnt[cur] > 1.0) {
34     double flow = cnt[cur] - 1.0;
35     cnt[cur] = 1.0;
36     dfs(d + 1, v[cur][0], flow / 2);
37     dfs(d + 1, v[cur][1], flow / 2);
38   }
39 }
40
41 int main() {
42 //  freopen("case.in", "r", stdin);
43   init();
44   cin >> n >> t;
45   for (int i = 0; i < t; i++) {
46     dfs(0, 1, 1.0);
47   }
48   int ans = 0;
49   for (int i = 1; i <= n * (n + 1) / 2; i++) if (cnt[i] >= 1.0) ans++;
50   cout << ans << endl;
51   return 0;
52 }```

``` 1 /*zhen hao*/
2 #include <bits/stdc++.h>
3 using namespace std;
4
5 #define lson l, m, rt*2
6 #define rson m + 1, r, rt*2+1
7 #define xx first
8 #define yy second
9
10 typedef pair<int,int> pii;
11 typedef long long ll;
12 typedef unsigned long long ull;
13
14 const int maxn = 1e5 + 100;
15 char s[maxn];
16 int n, k, len;
17 int cnta[maxn], cntb[maxn];
18
19 bool check(int m) {
20   int best = min(cnta[m - 1], cntb[m - 1]);
21   for (int i = 1; i + m <= len; i++) {
22     int tmp = min(cnta[i + m - 1] - cnta[i - 1], cntb[i + m - 1] - cntb[i - 1]);
23     best = min(best, tmp);
24   }
25   return best <= k;
26 }
27
28 int main() {
29 //  freopen("case.in", "r", stdin);
30   cin >> n >> k;
31   scanf("%s", s);
32   len = strlen(s);
33   int a = 0, b = 0, L = 0, R = len + 1;
34   for (int i = 0; i < len; i++) {
35     if (s[i] == ‘a‘) a++; else b++;
36     cnta[i] = a; cntb[i] = b;
37 //    cout << a << ‘ ‘ << b << endl;
38   }
39   while (R - L > 1) {
40     int M = (R + L) / 2;
41     if (check(M)) L = M;
42     else R = M;
43   }
44   printf("%d\n", L);
45   return 0;
46 }```

``` 1 /*zhen hao*/
2 #include <bits/stdc++.h>
3 using namespace std;
4
5 #define lson l, m, rt*2
6 #define rson m + 1, r, rt*2+1
7 #define xx first
8 #define yy second
9
10 typedef pair<int,int> pii;
11 typedef long long ll;
12 typedef unsigned long long ull;
13
14 const int maxn = 1e3 + 10, dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
15 char maze[maxn][maxn];
16 int vis[4][maxn][maxn], can[5][5][maxn][maxn];
17 int n, m, xt, yt, xm, ym;
18
19 struct Node {
20   int x, y, c, d;
21   Node(int x=0, int y=0, int c=0, int d=0) : x(x), y(y), c(c), d(d) {}
22 };
23
24 void init_graph() {
25   memset(can, 0, sizeof can);
26     for (int i = 0; i < n; i++)
27       for (int j = 0; j < m; j++) {
28         if(maze[i][j] == ‘+‘) can[0][0][i][j] = can[0][1][i][j] = can[0][2][i][j] = can[0][3][i][j] = 1;
29         if(maze[i][j] == ‘U‘) can[0][1][i][j] = can[0][2][i][j] = can[0][3][i][j] = 1;
30         if(maze[i][j] == ‘R‘) can[0][0][i][j] = can[0][2][i][j] = can[0][3][i][j] = 1;
31         if(maze[i][j] == ‘D‘) can[0][0][i][j] = can[0][1][i][j] = can[0][3][i][j] = 1;
32         if(maze[i][j] == ‘L‘) can[0][0][i][j] = can[0][1][i][j] = can[0][2][i][j] = 1;
33         if(maze[i][j] == ‘-‘) can[0][1][i][j] = can[0][3][i][j] = 1;
34         if(maze[i][j] == ‘|‘) can[0][0][i][j] = can[0][2][i][j] = 1;
35         if(maze[i][j] == ‘^‘) can[0][0][i][j] = 1;
36         if(maze[i][j] == ‘>‘) can[0][1][i][j] = 1;
37         if(maze[i][j] == ‘v‘) can[0][2][i][j] = 1;
38         if(maze[i][j] == ‘<‘) can[0][3][i][j] = 1;
39       }
40     for (int x = 1; x < 4; x++)
41       for (int i = 0; i < n; i++)
42         for (int j = 0; j < m; j++)
43           for (int k = 0; k < 4; k++)
44             can[x][(k + 1) % 4][i][j] = can[x - 1][k][i][j];
45 }
46
47 int bfs() {
48   queue<Node> q;
49   q.push(Node(xt, yt, 0, 0));
50   memset(vis, false, sizeof vis);
51   vis[0][xt][yt] = 1;
52   while (!q.empty()) {
53     Node r = q.front(); q.pop();
54     if (r.x == xm && r.y == ym) return r.d;
55
56     for (int i = 0; i < 4; i++) if (can[r.c][i][r.x][r.y]) {
57       int nx = r.x + dx[i], ny = r.y + dy[i];
58       if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
59       if (vis[r.c][nx][ny] || !can[r.c][(i + 2) % 4][nx][ny]) continue;
60       vis[r.c][nx][ny] = 1;
61       q.push(Node(nx, ny, r.c, r.d + 1));
62     }
63
64     int nc = (r.c + 1) % 4;
65     if (vis[nc][r.x][r.y]) continue;
66     vis[nc][r.x][r.y] = 1;
67     q.push(Node(r.x, r.y, nc, r.d + 1));
68   }
69   return -1;
70 }
71
72 int main() {
73 //  freopen("case.in", "r", stdin);
74   cin >> n >> m;
75   for (int i = 0; i < n; i++) {
76     scanf("%s", maze[i]);
77   }
78   scanf("%d%d%d%d", &xt, &yt, &xm, &ym);
79   xt--; yt--; xm--; ym--;
80 //  cout << xt << ‘ ‘ << yt << endl;
81   init_graph();
82   printf("%d\n", bfs());
83   return 0;
84 }```

P(x) = anxn + an - 1xn - 1 + ... + a1x + a0

J = ankn + an - 1kn - 1 + ... + a1k + a0，因为P（x） - J = an（x - k）（...） + an - 1(x - k) (...) + a1(x - k)，所以只要让这个J = 0就说明可以整除了，之后的情况就像上述博客说的那样了。最后提醒一点是：用这个博客的随机数的方法可以过，将数设为数据没有考虑的一个数也可以过。

``` 1 /*zhen hao*/
2 #include <bits/stdc++.h>
3 using namespace std;
4
5 typedef long long ll;
6 const int maxn = 1e5 + 10, mod = 100003619;
7 int a[maxn], t[maxn], n, k;
8 char s[110];
9
10 int main() {
11 //  freopen("case.in", "r", stdin);
12   cin >> n >> k;
13   int ok = 0, c = 0;
14   for (int i = 0; i <= n; i++) {
15     scanf("%s", s);
16     if (s[0] == ‘?‘) ok = 1;
17     else {
18       t[i] = 1;
19       sscanf(s, "%d", a + i);
20       c ^= 1;
21     }
22   }
23   if (k == 0) {
24     if (t[0]) puts(a[0] == 0 ? "Yes" : "No");
25     else puts(c & 1 ? "Yes" : "No");
26   } else {
27     if (ok) puts(n & 1 ? "Yes" : "No");
28     else {
29       ll res = 0;
30       for (int i = n; i >= 0; i--) {
31         res = res * k + a[i];
32         res %= mod;
33       }
34       puts(res == 0 ? "Yes" : "No");
35     }
36   }
37   return 0;
38 }```

## Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T

## Codeforces Round #354 (Div. 2) - B. Pyramid of Glasses

/* 队友告知的题意,大概是 杯子如题摆放,有 n 层 .最上面那个杯子一秒钟可以装满, 给出 n 和时间 t ,问 t 秒后可以装满多少个杯子. 大致思路是 使用二维数组模拟杯子往下漏水的过程. 最后扫一遍数组计算容量大于 1 的个数 . */ #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> using name

## Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

## 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