Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
题目连接:
http://codeforces.com/group/T0ITBvoeEx/contest/988/problem/E
Description
Polycarp lives on a coordinate line at the point x=0. He goes to his friend that lives at the point x=a. Polycarp can move only from left to right, he can pass one unit of length each second.
Now it's raining, so some segments of his way are in the rain. Formally, it's raining on n non-intersecting segments, the
i-th segment which is in the rain is represented as [li,ri] (0≤li<ri≤a).
There are m umbrellas lying on the line, the i-th umbrella is located at point xi (0≤xi≤a) and has weight pi. When Polycarp begins his journey, he doesn't have any umbrellas.
During his journey from x=0 to x=a Polycarp can pick up and throw away umbrellas. Polycarp picks up and throws down any umbrella instantly. He can carry any number of umbrellas at any moment of time. Because Polycarp doesn't want to get wet, he must carry at least one umbrella while he moves from x to x+1 if a segment [x,
x+1] is in the rain (i.e. if there exists some i such that li≤x and x+1≤ri).
The condition above is the only requirement. For example, it is possible to go without any umbrellas to a point where some rain segment starts, pick up an umbrella at this point and move along with an umbrella. Polycarp can swap umbrellas while he is in the rain.
Each unit of length passed increases Polycarp's fatigue by the sum of the weights of umbrellas he carries while moving.
Can Polycarp make his way from point x=0 to point x=a? If yes, find the minimum total fatigue after reaching x=a, if Polycarp picks up and throws away umbrellas optimally.
Sample Input
10 2 4
3 7
8 10
0 10
3 4
8 1
1 2
Sample Output
14
题意
有几段下雨的地方,有几把雨伞在地上,消耗的值为伞的重量*移动距离,问在不被淋湿的情况下,如何打伞消耗最小
题解:
dp[i]指的是从第i把伞开始打之后的最小消耗,他由dp[j] (j>i)转移而来。
时间复杂度O(m^2)
代码
#include <bits/stdc++.h>
using namespace std;
pair<int, int> r[2010];
pair<int, int> u[2010];
int n, m, a;
int h[2010];
int ans;
const int INF = 0x7fffffff;
int st, fn;
int main() {
//freopen("1.txt","r",stdin);
cin >> a;
cin >> n >> m;
st = INF;
fn = 0;
for (int i = 0; i < n; i++) {
cin >> r[i].first >> r[i].second;
st = min(st, r[i].first);
fn = max(fn, r[i].second);
}
for (int i = 0; i < m; i++) cin >> u[i].first >> u[i].second;
sort(u, u + m, [](const pair<int, int> &p, const pair<int, int> &q) { return p < q; });
for (int i = 0; i <= m; i++) {
h[i] = INF;
}
sort(r, r + n, [](const pair<int, int> &p, const pair<int, int> &q) { return p < q; });
for (int i = m - 1; i >= 0; i--) {
int index;
for (index = n - 1; index >= 0; index--)
if (r[index].first < u[i].first) break;
int cur = (fn > u[i].first ? fn - u[i].first : 0) * u[i].second;
h[i] = min(h[i], cur);
for (int j = 0; j < i; j++) {
int cur;
if (r[index].second > u[j].first) {
cur = (min(r[index].second, u[i].first) - u[j].first) * u[j].second;
} else {
cur = 0;
}
h[j] = min(h[j], h[i] + cur);
}
}
ans = INF;
for (int i = 0; i < m; i++) {
if (u[i].first <= st) ans = min(ans, h[i]);
}
if (ans == INF) ans = -1;
cout << ans << endl;
}
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas的更多相关文章
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #486 (Div. 3) E. Divisibility by 25
Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #486 (Div. 3) D. Points and Powers of Two
Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvo ...
- Codeforces Round #486 (Div. 3) A. Diverse Team
Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)
题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...
- Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...
- Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid
F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
随机推荐
- 把已经安装到C盘的软件完美移动到D盘
背景信息 今天早上在安装软件的时候发现C盘爆满,只剩下最后10G了.而我要安装的玩意儿必须装到C盘. 靠清理垃圾文件来解决并不是一个好方法,实际上通常垃圾文件占用很少,而且就算清理了,也还会再出现. ...
- 使用睿云智合开源 Breeze 工具部署 Kubernetes v1.12.3 高可用集群
一.Breeze简介 Breeze 项目是深圳睿云智合所开源的Kubernetes 图形化部署工具,大大简化了Kubernetes 部署的步骤,其最大亮点在于支持全离线环境的部署,且不需要FQ获取 G ...
- Spring MVC 之 请求url 带后缀的情况
RequestMappingInfoHandlerMapping 在处理http请求的时候, 如果 请求url 有后缀,如果找不到精确匹配的那个@RequestMapping方法.那么,就把后缀去掉, ...
- gopath环境变量设置
#在国内镜像下载二进制包 wget -c http://www.golangtc.com/static/go/go1.4.1.linux-amd64.tar.gz tar -C /usr/local ...
- java网络编程-单线程服务端与客户端通信
该服务器一次只能处理一个客户端请求;p/** * 利用Socket进行简单服务端与客户端连接 * 这是服务端 */public class EchoServer { private ServerSoc ...
- Java Day26进程01天
Java开启多个线程有两种方法,一种继承Thread类,一种实现Runnable接口.具体示例如下: 01继承Thread类 02实现Runnable接口
- Elasticsearch 整合spring(不是sprig boot)
公司做统计任务,有使用Es做聚合操作,使用的是自己封装的版本,这边整合下原生spring,做下学习记录,随便看一下,发现差不多都是spring boot的案例...我该怎么办,...发现整合的过程其实 ...
- 十六、Mediator 仲载者设计模式
原理: 代码清单: Mediator public interface Mediator { void createColleagues(); void colleagueChanged(); } C ...
- win7 win10下80端口被System进程占用的解决方法
用如下方法可以解决System进程占用80端口的问题:打开RegEdit:开始-运行-输入regedit-调出注册表找到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControl ...
- linux系统,服务器与服务器拷贝文件
服务器与服务器拷贝文件命令 scp -P (服务器端口)-r 拷贝文件名称列表 远程服务器用户@远程服务器ip :(文件放置目录) 1.将本地home目录下的apache-tomcat-8.0. ...