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 ...
随机推荐
- java课后作业
课后作业之字串加密: 设计思想: 1.输入要加密的英文子串str 2.定义num=str的字符串长度 3.将字符串转化为单个字符 4.每个字符+3,向后移3个 5.定义str1,将新得到的每个字符加到 ...
- 使用BAT安装 Windows Service
脚本如下: @echo off @setlocal enableextensions @cd /d "%~dp0" set InstallPath=C:\DBoxService\S ...
- [Android Pro] 告别编译运行 ---- Android Studio 2.0 Preview发布Instant Run功能
reference to : http://www.cnblogs.com/soaringEveryday/p/4991563.html 以往的Android开发有一个头疼的且拖慢速度的问题,就是你每 ...
- 昨天一日和彭讨论post请求数据的问题
上午写了一个for循环,下午与同学视频才知道没有解决根本问题,接口是url单个的数据请求,而导入的是多个员工的考勤数据也就是要有多个请求同时发出,利用这个做法是有链接超时的情况,所以昨天晚上彭为了导入 ...
- logstash之multiline插件,匹配多行日志
在外理日志时,除了访问日志外,还要处理运行时日志,该日志大都用程序写的,比如log4j.运行时日志跟访问日志最大的不同是,运行时日志是多行,也就是说,连续的多行才能表达一个意思. 在filter中,加 ...
- 关闭 Visual Studio 2013 的 Browser Link 功能
最近公司弄新项目需要用 MVC,就把 IDE 升级到了 Visual Studio 2013,在开发的时候发现有好多请求一个本地49925的端口 . 很奇怪,一开始以为是 Visual Studio ...
- 【SQL】检索满足条件的最大值的数据集合
是不是看题目觉的看不懂?其实我自己也看不懂,但是又找不到更好的词来形容. 为了更好的表达我的意思,请看下. 如果有一张成绩表(Points), 学生(student) 成绩(point) 科目(sub ...
- Delphi中的基础数据类型
参考http://www.cnblogs.com/del/archive/2007/12/04/982167.html 在学习之初,在这么多的数据类型中,最好记住这五种标准数据类型(整型.实型.字符型 ...
- 攻城狮在路上(壹) Hibernate(六)--- 通过Hibernate操纵对象(上)
一.Hibernate缓存简介: Session接口是Hibernate向应用程序提供的操纵数据接口的最主要接口,它提供了基本的保存.更新.删除和加载Java对象的方法. Session具有一个缓存, ...
- js注入
1.JavaScript注入就是在浏览器地址栏中输入一段js代码,用来改变页面js变量.页面标签的内容. 使用Javascript注入,用户不需要关闭或保存网页就可以改变其内容,这是在浏览器的地址栏上 ...