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 ...
随机推荐
- jQuery与JS的区别,以及jQuery的基础语法
*在使用jQuery时,要在页面最上端加上 <script src="../jquery-1.11.2.min.js"></script> 看一下js与jQ ...
- osg绘制一个球体
//By smells2 at Lab 2012-02-21#include <osg/Group>#include <osg/Geode>#include <osg/S ...
- [Ubuntu] ubuntu10.04系统维护之Wine的安装
在介绍安装wine之前,我想是有必要先介绍一下Wine的.当然,如果是Liunx的高手,我想是没必要看的,但是对于笔者这样的菜鸟级人物还是需要看一下的. Wine是一款Liunx下的模拟器软件,但是W ...
- September 8th 2016 Week 37th Thursday
The secret of high-impact business is early preparation. 高效商务,赢在未雨绸缪. Early and best preparation is ...
- CentOS yum的详细使用方法
yum是什么yum = Yellow dog Updater, Modified主要功能是更方便的添加/删除/更新RPM包.它能自动解决包的倚赖性问题.它能便于管理大量系统的更新问题yum特点可以同时 ...
- 无根树转有根树(dfs,tree)
#include <bits/stdc++.h> #include <iostream> #include <queue> #include <stdio.h ...
- hdu 2159 FATE
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2159 思路:二维完全背包,状态转移方程为: f[j][l]=max(f[j][l],f[j-b[i]] ...
- 关于Python 获取windows信息收集
收集一些Python操作windows的代码 (不管是自带的or第三方库)均来自网上 1.shutdown 操作 定时关机.重启.注销 #!/usr/bin/python #-*-coding:utf ...
- Tiny Rss Reader - 迷你RSS阅读器
发布新软件 TinyRss: Windows平台上的一个小巧的Rss阅读器. 用户界面: 项目地址: https://github.com/movsb/tinyrss.git 测试下载: http:/ ...
- hdu 5294 最短路+最大流 ***
处理处最短路径图,这个比较巧妙 链接:点我