日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #354 (Div. 2)

發(fā)布時間:2023/12/18 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #354 (Div. 2) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

貪心 A Nicholas and Permutation

#include <bits/stdc++.h>typedef long long ll; const int N = 1e5 + 5; int a[105]; int pos[105];int main() {int n;scanf ("%d", &n);for (int i=1; i<=n; ++i) {scanf ("%d", a+i);pos[a[i]] = i;}int ans = abs (pos[1] - pos[n]);if (pos[n] != 1) {ans = std::max (ans, abs (pos[n] - 1));}if (pos[n] != n) {ans = std::max (ans, abs (pos[n] - n));}if (pos[1] != 1) {ans = std::max (ans, abs (pos[1] - 1));}if (pos[1] != n) {ans = std::max (ans, abs (pos[1] - n));}printf ("%d\n", ans);return 0; }

模擬+DFSB Pyramid of Glasses

設(shè)酒杯滿了值為1.0,每一次暴力傳遞下去

#include <bits/stdc++.h>typedef long long ll; const int N = 1e5 + 5; double a[15][15]; int n;void DFS(int x, int y, double v) {if (x == n + 1 || v == 0) {return ;}if (a[x][y] == 1.0) {DFS (x + 1, y, v / 2);DFS (x + 1, y + 1, v / 2);} else {double sub = 1.0 - a[x][y];if (sub <= v) {a[x][y] = 1.0;DFS (x + 1, y, (v - sub) / 2);DFS (x + 1, y + 1, (v - sub) / 2);} else {a[x][y] += v;}} }int main() {int t;scanf ("%d%d", &n, &t);for (int i=1; i<=t; ++i) {DFS (1, 1, 1.0);}int ans = 0;for (int i=1; i<=n; ++i) {for (int j=1; j<=i+1; ++j) {if (a[i][j] == 1.0) {ans++;}}}printf ("%d\n", ans);return 0; }

尺取法(two points) C Vasya and String

從左到右維護(hù)一段連續(xù)的區(qū)間,改變次數(shù)不大于k,取最大值.

#include <bits/stdc++.h>const int N = 1e5 + 5; char str[N]; int n, m;void solve() {int c[2] = {0};int ans = 0;for (int i=0, j=0; i<n; ++i) {while (j < n) {c[str[j] == 'a' ? 0 : 1]++;if (std::min (c[0], c[1]) <= m) {++j;} else {c[str[j] == 'a' ? 0 : 1]--;break;}}ans = std::max (ans, j - i);c[str[i] == 'a' ? 0 : 1]--;}printf ("%d\n", ans); }int main() {scanf ("%d%d", &n, &m);scanf ("%s", str);solve ();return 0; }

BFS(方向,旋轉(zhuǎn))?D Theseus and labyrinth

多加一維表示旋轉(zhuǎn)次數(shù)(0~3),dis[x][y][z]表示走到(x, y)旋轉(zhuǎn)z次后的最小步數(shù).

#include <bits/stdc++.h>const int N = 1e3 + 5; const int INF = 0x3f3f3f3f; int dx[] = {0, -1, 0, 1}; int dy[] = {1, 0, -1, 0}; bool dir[N][N][4]; int dis[N][N][4]; char str[N]; struct Point {int x, y, d; }; int n, m; int sx, sy, ex, ey;bool judge(int x, int y) {if (x < 0 || x >= n || y < 0 || y >= m) {return false;} else {return true;} }int BFS() {memset (dis, INF, sizeof (dis));dis[sx][sy][0] = 0;std::queue<Point> que;que.push ((Point) {sx, sy, 0});while (!que.empty ()) {Point p = que.front (); que.pop ();int &pd = dis[p.x][p.y][p.d];int td = (p.d + 1) % 4;if (dis[p.x][p.y][td] > pd + 1) {dis[p.x][p.y][td] = pd + 1;que.push ((Point) {p.x, p.y, td});}for (int i=0; i<4; ++i) {int tx = p.x + dx[i];int ty = p.y + dy[i];if (!judge (tx, ty)) {continue;}if (dir[p.x][p.y][(p.d+i)%4] && dir[tx][ty][(p.d+i+2)%4]) {if (dis[tx][ty][p.d] > pd + 1) {dis[tx][ty][p.d] = pd + 1;que.push ((Point) {tx, ty, p.d});}}}}int ret = INF;for (int i=0; i<4; ++i) {ret = std::min (ret, dis[ex][ey][i]);}return (ret != INF ? ret : -1); }int main() {scanf ("%d%d", &n, &m);for (int i=0; i<n; ++i) {scanf ("%s", str);for (int j=0; j<m; ++j) {char ch = str[j];if (ch=='+' || ch=='-' || ch=='>' || ch=='U' || ch=='L' || ch=='D') dir[i][j][0] = true;if (ch=='+' || ch=='|' || ch=='^' || ch=='R' || ch=='L' || ch=='D') dir[i][j][1] = true;if (ch=='+' || ch=='-' || ch=='<' || ch=='R' || ch=='U' || ch=='D') dir[i][j][2] = true;if (ch=='+' || ch=='|' || ch=='v' || ch=='R' || ch=='U' || ch=='L') dir[i][j][3] = true;}}scanf ("%d%d%d%d", &sx, &sy, &ex, &ey);sx--; sy--; ex--; ey--;printf ("%d\n", BFS ());return 0; }

數(shù)學(xué) E The Last Fight Between Human and AI

原題轉(zhuǎn)化為求P(k)==0.如果k==0,判斷a[0]是否能被玩家設(shè)置成0.否則判斷剩余數(shù)字個數(shù)的奇偶以及現(xiàn)在是誰出手,判斷最后一步是否為玩家走,最后一步總能使得P(k)==0.

#include <bits/stdc++.h>typedef long long ll; const int N = 1e5 + 5;int read() {int ret = 0, f = 1;char ch = getchar ();while (ch < '0' || ch > '9') {if (ch == '?') {return -11111;}if (ch == '-') {f = -1;}ch = getchar ();}while (ch >= '0' && ch <= '9') {ret = ret * 10 + (ch - '0');ch = getchar ();}return ret * f; }int a[N];int main() {int n, k;scanf ("%d%d", &n, &k);int who = 0, m = 0;for (int i=0; i<=n; ++i) {a[i] = read ();if (a[i] != -11111) {who = 1 ^ who; //0: Computer, 1: player} else {m++;}}if (k == 0) {if (a[0] == -11111) {if (!who) {puts ("No");} else {puts ("Yes");}} else {if (a[0] == 0) {puts ("Yes");} else {puts ("No");}}} else {if (m & 1) {if (!who) {puts ("No");} else {puts ("Yes");}} else {if (m > 0) {if (!who) {puts ("Yes");} else {puts ("No");}} else {double sum = 0;for (int i=n; i>=0; --i) {sum = sum * k + a[i];}if (fabs (sum - 0) < 1e-8) {puts ("Yes");} else {puts ("No");}}}}return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/Running-Time/p/5545782.html

總結(jié)

以上是生活随笔為你收集整理的Codeforces Round #354 (Div. 2)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。