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 ...
随机推荐
- 详解web.xml中元素的加载顺序
一.背景 最近在项目中遇到了启动时出现加载service注解注入失败的问题,后来经过不懈努力发现了是因为web.xml配置文件中的元素加载顺序导致的,那么就抽空研究了以下tomcat在启动时web.x ...
- Linux mpstat字段解析
mpstat是Multiprocessor Statistics的缩写,是实时系统监控工具.其报告与CPU的一些统计信息,这些信息存放在/proc/stat文件中.在多CPUs系统里,其不但能查看所有 ...
- 创建INnodb的compress表
需要将innodb_file_per_table=1 ,innodb_file_format=Barracuda;; 如: Creating a Compressed Table in a Gener ...
- DB2 嵌入式应用中定义游标(开放平台上)
DECLARE CURSOR statement The DECLARE CURSOR statement defines a cursor. Invocation Although an inter ...
- Quartus ii 12.1软件破解之后编译原有的工程出现报警错误的解决办法
在Quartus ii 12.1软件破解之后,想用来编译原来编译过的工程,但是编译到最后出现下面两个错误警告: 原来以为没有破解成功或者安装的时候有文件被杀毒软件吃了,导致安装错误,又重新安装了两次都 ...
- LR结果分析——TPS和吞吐率
针对吞吐率和TPS的关系,这个在结果分析中如何使用,就个人经验和朋友讨论后,提出如下建议指导,欢迎同僚指正. TPS:transaction per second 服务器每秒处理的事务数. 吞吐率:测 ...
- 通过btn获取所在cell
[cell.btn addTarget:self action:@selector(cellBtnClicked:event:) forControlEvents:UIControlEventTouc ...
- Android Studio 生成Jar包时遇到的gradlew下载问题
网上介绍说使用gradlew打包jar,可是输入gradlew makeJar后就开始download XXX.zip,但是等了很久都没有完成.解决办法如下: 原文:http://blog.csdn ...
- Clr Via C#读书笔记---I/O限制的异步操作
widows如何执行I/O操作 构造调用一个FileStream对象打开一个磁盘文件-----FileStream.Read方法从文件中读取数据(此时线程从托管代码转为本地/用户模式代码)- ...
- linux中创建gpio节点
转自:http://blog.chinaunix.net/uid-29165999-id-4296162.html #define GPIO_MAJOR 230 // major device NO. ...