Codeforces Round #354 (Div. 2)

 

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/457846.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux c程序中内核态与用户态内存存储问题

Unix/Linux的体系架构 如上图所示&#xff0c;从宏观上来看&#xff0c;Linux操作系统的体系架构分为用户态和内核态&#xff08;或者用户空间和内核&#xff09;。内核从本质上看是一种软件——控制计算机的硬件资源&#xff0c;并提供上层应用程序运行的环境。用户态即上层应…

线程自动退出_C++基础 多线程笔记(一)

join & detachjoin和detach为最基本的用法&#xff0c;join可以使主线程&#xff08;main函数&#xff09;等待子线程&#xff08;自定义的function_1函数&#xff09;完成后再退出程序&#xff0c;而detach可以使子线程与主线程毫无关联的独立运行&#xff0c;当主线程执行…

WEB在线预览PDF

这是我在博客园发表的第一篇文章。以后会陆续把在线预览其他格式文档的解决方案发表出来。 解决思路&#xff1a;把pdf转换成html显示。 在线预览pdf我暂时了解3种解决方案&#xff0c;欢迎大家补充。 方案一&#xff1a; 利用pdf2html软件将PDF转换成HTML。 用法: PDF2HTML [选…

[算法]判断一个数是不是2的N次方

如果一个数是2^n&#xff0c;说明这个二进制里面只有一个1。除了1. a (10000)b a-1 (01111)b a&(a-1) 0。 如果一个数不是2^n&#xff0c; 说明它的二进制里含有多一个1。 a (1xxx100)b a-1(1xxx011)b 那么 a&(a-1)就是 (1xxx000)b&#xff0c; 而不会为0。 所以可…

VMware Ubuntu 全屏问题解决

在终端中输入&#xff1a; sudo apt install open-vm* 回车 自动解决

数组拼接时中间怎么加入空格_【题解二维数组】1123:图像相似度

1123&#xff1a;图像相似度时间限制: 1000 ms 内存限制: 65536 KB【题目描述】给出两幅相同大小的黑白图像(用0-1矩阵)表示&#xff0c;求它们的相似度。说明&#xff1a;若两幅图像在相同位置上的像素点颜色相同&#xff0c;则称它们在该位置具有相同的像素点。两幅图像的…

(旧)子数涵数·C语言——条件语句

首先&#xff0c;我们讲一下理论知识&#xff0c;在编程中有三种结构&#xff0c;分别是顺序结构、条件结构、循环结构&#xff0c;如果用流程图来表示的话就是&#xff1a; 那么在C语言中&#xff0c;如何灵活运用这三种结构呢&#xff1f;这就需要用到控制语句了。 而条件语句…

apache.commons.lang.StringUtils 使用心得

apache.commons.lang.StringUtils 使用心得 转载于:https://www.cnblogs.com/qinglizlp/p/5549687.html

python哪个版本支持xp_windows支持哪个版本的python

Windows操作系统支持Python的Python2版本和Python3版本&#xff0c;下载安装时要根据windows的操作系统来选择对应的Python安装包&#xff0c;否则将不能安装成功。 Python是跨平台的&#xff0c;免费开源的一门计算机编程语言。是一种面向对象的动态类型语言&#xff0c;最初被…

Ubuntu 键盘错位解决 更改键盘布局

原因是键盘布局不能适应键盘 解绝方法&#xff1a;更改键盘布局 一般改为标准104键盘就行 在终端输入 sudo dpkg-reconfigure keyboard-configuration 选择 标准104键盘 然后一直回车就行

【No.1 Ionic】基础环境配置

Node 安装git clone https://github.com/nodejs/node cd node ./configure make sudo make install node -v npm -vnpm设置淘宝镜像npm config set registry https://registry.npm.taobao.org npm config set disturl https://npm.taobao.org/distIOS Simulatorsudo npm instal…

识别操作系统

使用p0f进行操作系统探测 p0f是一款被动探测工具&#xff0c;通过分析网络数据包来判断操作系统类型。目前最新版本为3.06b。同时p0f在网络分析方面功能强大&#xff0c;可以用它来分析NAT、负载均衡、应用代理等。 p0f的命令参数很简单&#xff0c;基本说明如下&#xff1a; l…

常用RGB颜色表

转载于:https://www.cnblogs.com/Itwonderful/p/5550800.html

python中seek函数的用法_在Python中操作文件之seek()方法的使用教程

seek()方法在偏移设定该文件的当前位置。参数是可选的&#xff0c;默认为0&#xff0c;这意味着绝对的文件定位&#xff0c;它的值如果是1&#xff0c;这意味着寻求相对于当前位置&#xff0c;2表示相对于文件的末尾。 没有返回值。需要注意的是&#xff0c;如果该文件被打开或…

WPF中Grid实现网格,表格样式通用类(转)

/// <summary> /// 给Grid添加边框线 /// </summary> /// <param name"grid"></param> public static void InsertFrameForGrid(Grid grid) { var rowcon grid.RowDefinitions.Count; var clcon grid.ColumnDefinitions.Count; for (var i…

VS2017 安装 QT5.9

VS2017专业版使用最新版Qt5.9.2教程&#xff08;最新教材&#xff09; 目录 VS2017专业版使用最新版Qt5.9.2教程&#xff08;最新教材&#xff09; 运行环境&#xff1a; 1.安装Qt5.9.2 2.安装Qt5.9与VS2017之间的插件: 3.配置Qt VS Tool的环境. 4.设置创建的Qt的项目的属…

异步与并行~ReaderWriterLockSlim实现的共享锁和互斥锁

返回目录 在System.Threading.Tasks命名空间下&#xff0c;使用ReaderWriterLockSlim对象来实现多线程并发时的锁管理&#xff0c;它比lock来说&#xff0c;性能更好&#xff0c;也并合理&#xff0c;我们都知道lock可以对代码块进行锁定&#xff0c;当多线程共同访问代码时&am…

linux ssh yum升级_Linux 运维必备的 13 款实用工具,拿好了

作者丨Erstickthttp://blog.51cto.com/13740508/2114819本文介绍几款 Linux 运维比较实用的工具&#xff0c;希望对 Linux 运维人员有所帮助。1. 查看进程占用带宽情况 - NethogsNethogs 是一个终端下的网络流量监控工具可以直观的显示每个进程占用的带宽。下载&#xff1a;htt…

iOS应用如何支持IPV6

本文转自 http://www.code4app.com/forum.php?modviewthread&tid8427&highlightipv6 果然是苹果打个哈欠&#xff0c;iOS行业内就得起一次风暴呀。自从5月初Apple明文规定所有开发者在6月1号以后提交新版本需要支持IPV6-Only的网络&#xff0c;大家便开始热火朝天的研…

SQL Server -- SQLserver 存储过程执行错误记录到表

SQLserver 存储过程执行错误记录到表 From: http://blog.csdn.net/leshami/article/details/51333650 对于在执行存储过程中碰到的一些错误&#xff0c;如果未及时捕获或者说传递给前端应用程序来&#xff0c;在这样的情形下&#xff0c;故障的排查显得尤为困难。基于此&…