贪心 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

设酒杯满了值为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

从左到右维护一段连续的区间,改变次数不大于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(方向,旋转) D Theseus and labyrinth

多加一维表示旋转次数(0~3),dis[x][y][z]表示走到(x, y)旋转z次后的最小步数.

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

数学 E The Last Fight Between Human and AI

原题转化为求P(k)==0.如果k==0,判断a[0]是否能被玩家设置成0.否则判断剩余数字个数的奇偶以及现在是谁出手,判断最后一步是否为玩家走,最后一步总能使得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;
}

转载于:https://www.cnblogs.com/Running-Time/p/5545782.html

Codeforces Round #354 (Div. 2)相关推荐

  1. Codeforces Round #354 (Div. 2)-A

    A. Nicholas and Permutation 题目链接:http://codeforces.com/contest/676/problem/A Nicholas has an array a ...

  2. Codeforces Round #354 (Div. 2) A. Nicholas and Permutation

    Nicholas and Permutation time limit : 1 second memory limit: 256 megabytes 题目连接: http://www.codeforc ...

  3. Codeforces Round #354 (Div. 2)-Theseus and labyrint

    原文链接 题中给的迷宫有四个状态,我把每个状态对应的图都生成.用宽搜求出从原点到每个状态的迷宫的每个格子的最小距离. #include <iostream> #include <cs ...

  4. Codeforces Round #354 (Div. 2) D. Theseus and labyrinth(bfs)

    题意:给出一个n*m的地图,英雄从(xt,yt)出发,要到达敌人所在地(xm,ym).地图每个格子有设定: ^>v<代表向箭头方向有门,其他方向没门: URDL代表某个方向没门,其他方向都 ...

  5. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  6. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  7. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  8. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  9. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

最新文章

  1. Java虚拟机必学之四大知识要点,附学习资料
  2. Java命令行界面(第24部分):MarkUtils-CLI
  3. js 调用服务器端方法总结
  4. 【qduoj - 1012】反转数字(模拟,水题)
  5. 关于Image创建的内存管理
  6. Linux常用命令笔记---创建私有YUM源
  7. pip 更新版本失败问题解决
  8. jpcap的配置方法
  9. python免费课程400节-小码王少编程经典课程都有哪几个 这里揭晓
  10. 1. thinkphp (1)
  11. 编译WINDOWS版FFmpeg:编译x264
  12. hashmap containsvalue时间复杂度_恕我直言,你真的了解HashMap吗?
  13. MySQL的InnoDB存储引擎
  14. 计算机cpu和内存不足,电脑内存不足的解决方法
  15. 计算机系统无法启动 错误恢复怎么办,win7系统无法启动 安全模式也进入不了怎么办-win7启动失败,win7错误恢复无法开机...
  16. 如何实现简单的随机点名
  17. draftsight linux 32,DraftSight停止提供Linux版:所有免费版将于2019年12月31日后停止运行...
  18. Android zxing,轻松实现二维码扫描、生成
  19. ArcGIS基础实验操作100例--实验76按格网统计点要素
  20. 中国公交查询系统(busmaster) v1.1 怎么用

热门文章

  1. 【蓝桥杯官网试题 -算法训练】素因子去重(数学,数论,因子约数)
  2. 【HDU - 1025】Constructing Roads In JGShining's Kingdom(dp最长上升子序列模型 + 二分优化)
  3. HDU 3785 寻找大富翁(sort排序或优先队列)
  4. VMware虚拟机下安装Ubuntu16.04镜像完整教程
  5. 图解算法学习笔记(四):快速排序
  6. 撞球编程c语言,急!C语言编程题——撞球
  7. 升级bios_华硕B350PLUS升级BIOS更换AMD 3900X步骤
  8. 掩膜区域内像素值_MRI ADC值是怎么来的?咱们来手算一下
  9. java ajax 导出excel文件_springMVC(4)---生成excel文件并导出
  10. linux 计划任务格式,linux crontab 定时任务格式和使用方法2019-01-13