Codeforces Round #335 (Div. 2)
这题也卡了很久很久,关键是“至少”,所以只要判断多出来的是否比需要的多就行了。
#include <bits/stdc++.h>
using namespace std; #define lson l, mid, o << 1
#define rson mid + 1, r, o << 1 | 1
typedef long long ll;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f; int main(void) {
int a, b, c;
int x, y, z;
scanf ("%d%d%d", &a, &b, &c);
scanf ("%d%d%d", &x, &y, &z);
bool flag = true;
if (a < x || b < y || c < z) flag = false;
int s1 = a + b + c;
int s2 = x + y + z;
if (flag) puts ("Yes");
else if (s1 < s2) puts ("No");
else {
int less = 0, more = 0;
if (a < x) less += x - a;
else {
more += (a - x) / 2;
}
if (b < y) less += y - b;
else {
more += (b - y) / 2;
}
if (c < z) less += z - c;
else {
more += (c - z) / 2;
}
if (more >= less) puts ("Yes");
else puts ("No");
} return 0;
}
题意:机器人按照指令走,问有几个格子能使的在第i步使机器人爆炸。
分析:没什么难的,走过了就vis掉。比赛时C做的人多,B没读懂放弃了。。
#include <bits/stdc++.h>
using namespace std; #define lson l, mid, o << 1
#define rson mid + 1, r, o << 1 | 1
typedef long long ll;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
char str[N];
bool vis[505][505];
int ans[N];
int n, m, x, y; int main(void) {
scanf ("%d%d%d%d", &n, &m, &x, &y);
scanf ("%s", str + 1);
int len = strlen (str + 1);
str[0] = '#'; ans[len] = n * m;
for (int i=0; i<len; ++i) {
if (i != 0) {
if (str[i] == 'U' && x > 1) x--;
else if (str[i] == 'D' && x < n) x++;
else if (str[i] == 'L' && y > 1) y--;
else if (str[i] == 'R' && y < m) y++;
}
if (vis[x][y]) ans[i] = 0;
else {
vis[x][y] = true;
ans[i] = 1; ans[len]--;
}
}
for (int i=0; i<=len; ++i) {
printf ("%d%c", ans[i], i == len ? '\n' : ' ');
} return 0;
}
构造+贪心 C - Sorting Railway Cars
题意:每一辆车可以去头或者尾,问最少几次能使排列有序
分析:贪心的思想,把相邻数字(LIS的不一定是相邻的,有问题)排列已经有序的不动,其他的都只要动一次就能有序。
#include <bits/stdc++.h>
using namespace std; #define lson l, mid, o << 1
#define rson mid + 1, r, o << 1 | 1
typedef long long ll;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int a[N], p[N]; int main(void) {
int n; scanf ("%d", &n);
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]); p[a[i]] = i;
}
int ans = 1, len = 1;
for (int i=2; i<=n; ++i) {
if (p[i] > p[i-1]) len++;
else len = 1;
ans = max (ans, len);
}
printf ("%d\n", n - ans); return 0;
}
Codeforces Round #335 (Div. 2)的更多相关文章
- Codeforces Round #335 (Div. 2) B. Testing Robots 水题
B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...
- Codeforces Round #335 (Div. 1) C. Freelancer's Dreams 计算几何
C. Freelancer's Dreams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contes ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 构造
D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...
- Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 动态规划
C. Sorting Railway Cars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/conte ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 水题
A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造
题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 模拟
A. Magic Spheres Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心
D. Lazy Student Student Vladislav came to his programming exam completely unprepared as usual. He ...
- Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 连续LIS
C. Sorting Railway Cars An infinitely long railway has a train consisting of n cars, numbered from ...
随机推荐
- 3ds max移除几何体的线段
将几何体转化成可编辑多边形,然后选中线段,调出上图的模式,然后选中删除.
- oracle 监控
sqlplus "/as sysdba" .监控当前数据库谁在运行什么SQL语句 SELECT osuser, username, sql_text from v$session ...
- 点击按钮对两个div的隐藏与显示进行切换
HTML: <button type="button" id="showHidden">点击切换div的隐藏与显示</button> ...
- 二维码相关工具Qrcode笔记
- Android -- View setScale, setTranslation 对View矩阵的处理
参考: 1.Android Matrix理论与应用详解 2.2D平面中关于矩阵(Matrix)跟图形变换的讲解 3.Android中关于矩阵(Matrix)前乘后乘的一些认识 4.Android Ma ...
- jquery学习笔记-----事件和动画
一.ready机制 $(document).ready( function(){} ) $().ready( function(){} ) $( function(){} ) jquery的read ...
- VS2012/2013 停止调试后,无法刷新页面
- Delphi线程的终止
当线程对象的Execute()执行完毕,我们就认为此线程终止了.这时候,它会调用Delphi的一个标准例程EndThread(),这个例程再调用API函数ExitThread().由ExitThrea ...
- 【JAVA常用类演示】
一.java.lang.System类. public final class Systemextends Object 该类包含一些有用的类字段和方法.它不能被实例化. 在 System 类提供的 ...
- 三、spinner
今天 ,看的和学的都不多,就弄了一个spinner控件而已,下面就记录一下spinner 用法吧 基本上说,使用spinner 有三个步骤 一.在布局文件里面设置spinner 控件,这个不用再多说了 ...