Codeforces Round #354 (Div. 2)
#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;
}
Codeforces Round #354 (Div. 2)的更多相关文章
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #354 (Div. 2)-D
D. Theseus and labyrinth 题目链接:http://codeforces.com/contest/676/problem/D Theseus has just arrived t ...
- Codeforces Round #354 (Div. 2)-C
C. Vasya and String 题目链接:http://codeforces.com/contest/676/problem/C High school student Vasya got a ...
- Codeforces Round #354 (Div. 2)-B
B. Pyramid of Glasses 题目链接:http://codeforces.com/contest/676/problem/B Mary has just graduated from ...
- Codeforces Round #354 (Div. 2)-A
A. Nicholas and Permutation 题目链接:http://codeforces.com/contest/676/problem/A Nicholas has an array a ...
- Codeforces Round #354 (Div. 2) D. Theseus and labyrinth
题目链接: http://codeforces.com/contest/676/problem/D 题意: 如果两个相邻的格子都有对应朝向的门,则可以从一个格子到另一个格子,给你初始坐标xt,yt,终 ...
- Codeforces Round #354 (Div. 2) C. Vasya and String
题目链接: http://codeforces.com/contest/676/problem/C 题解: 把连续的一段压缩成一个数,对新的数组求前缀和,用两个指针从左到右线性扫一遍. 一段值改变一部 ...
- Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)
题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...
- Codeforces Round #354 (Div. 2) E. The Last Fight Between Human and AI 数学
E. The Last Fight Between Human and AI 题目连接: http://codeforces.com/contest/676/problem/E Description ...
- Codeforces Round #354 (Div. 2) D. Theseus and labyrinth bfs
D. Theseus and labyrinth 题目连接: http://www.codeforces.com/contest/676/problem/D Description Theseus h ...
随机推荐
- XInitThreads与XLIB
XInitThreads函数通常需要尽早调用,一般要在XLIB的其他函数前调用 否则XLIB的函数可能会在调用时直接崩溃(多线程程序中) 最好的做法是,在main入口即调用XInitThreads函数
- jQuery-3~4章
jQuery-3~5章 JQuery003-JQuery中的DOM操作 jQuery中的DOM操作: 1.查找节点 A.查找元素节点 B. 查找属性节点 var s1 = $("ul li: ...
- shell判断条件整理
1.字符串判断 str1 = str2 当两个字符串串有相同内容.长度时为真 str1 != str2 当字符串str1和str2不等时为真 -n str1 当字符串的长度大于0时为真(串非空) -z ...
- 初学Java 精简知识点总结
面对Java丰富的知识资料,很多初学者难免觉得迷惘,该学什么,怎么去学?下面给大家讲Java基础知识做了精简总结,来帮助你梳理学习思路,赶快看看吧! 方法/步骤1 对象的初始化(1) 非静态对象的初始 ...
- HTML5学习笔记(持续更新中....)
平时的工作中,不知不觉我们应用了很多HTML5,但当正儿八经问起来你对HTML5了解多少,很多时候都有点懵. 做个简单的HTML5总结.包括简介.要学的知识点.凌乱的知识点 HMTL5简介 定义:ht ...
- 使用 JavaScript 实现简单候选项推荐功能(模糊搜索)【收藏】【转】
当我们使用 Google 等搜索功能时,会出现与搜索内容有关的候选项.使用 JavaScript 搜索字符串,通常会使用 indexOf 或者 search 函数,但是非常僵硬,只能搜索匹配特定词语. ...
- Excel 函数VLOOKUP初学者使用指南
1.基础说明 =VLOOKUP(lookup_value,tabble_array,col_index_num,(range_lookup)) lookup_value:用什么查找 tabble_ar ...
- Hadoop-HBASE案例分析-Hadoop学习笔记<二>
之前有幸在MOOC学院抽中小象学院hadoop体验课. 这是小象学院hadoop2.X概述第八章的笔记 主要介绍HBase,一个分布式数据库的应用案例. 案例概况: 1)时间序列数据库(OpenTSD ...
- Java多态与反射
多态通过分离做什么和怎么做,从另一个角度将接口与实现分离开来:通过多态来消除类型之间的耦合关系,在Java中,多态也叫动态绑定,后期绑定或运行时绑定,那么什么是方法绑定? 方法调用绑定: 将一个方法与 ...
- Linux 下测试网卡性能命令iperf 的用法
很多文件系统都自带iperf 命令,所以不用作多的移植工作. 如下查看他的帮助信息. Qt@aplex:~$ iperf -h Usage: iperf [-s|-c host] [options] ...