0526 HDU#5477&G2n#A-A Sweet Journey
来源:互联网 发布:手机韩剧网下载软件 编辑:程序博客网 时间:2024/05/22 15:50
摘要:
按照一定的消耗方式,如何最少的使用能量。
原题目链接:HDU - 5477
Sweet Journey
Master Di plans to take his girlfriend for a travel by bike. Their journey, which can be seen as a line segment of length L, is a road of swamps and flats. In the swamp, it takes A point strengths per meter for Master Di to ride; In the flats, Master Di will regain B point strengths per meter when riding. Master Di wonders:In the beginning, he needs to prepare how much minimum strengths. (Except riding all the time,Master Di has no other choice)
For each test case:
The first line contains four integers, n, A, B, L.
Next n lines, each line contains two integers:
Make sure intervals are not overlapped which means
Others are all flats except the swamps.
Please output “Case #k: answer”(without quotes) one line, where k means the case number counting from 1, and the answer is his minimum strengths in the beginning.
12 2 2 51 23 4
Case #1: 0来源: https://cn.vjudge.net/problem/description/56056?1495774615000
题目认识:
假定开始时已经是恰好最优状态 并设为状态0,依照消耗方式进行模拟。最后看状态的值是多少即可确定开始时的最低是多少。
注意:
计算需要补给的是多少。其他的不用改变状态值。
日期:
2017 5 26
代码:
#include <cstdio>
#include <algorithm>
#define MAX 0
int getans(){
int n,A,B,L;
int need=0,s=0;//strength
int li,ri,lastRi=0;
scanf("%d%d%d%d",&n,&A,&B,&L);
while(n--){
scanf("%d%d",&li,&ri);
s+=B*(li-lastRi);
s-=A*(ri-li);
if(s<0){need+=s;s=0;}
lastRi=ri;
}
return -need;
}
int main(){
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++){
printf("Case #%d: %d\n",i,getans());
}
return 0;
}
阅读全文
0 0
- 0526 HDU#5477&G2n#A-A Sweet Journey
- HDU 5477: A Sweet Journey
- hdu 5477 A Sweet Journey
- HDU 5477 A Sweet Journey
- HDU 5477 A Sweet Journey
- HDU 5477 A Sweet Journey
- HDU 5477 A Sweet Journey
- HDU 5477 A Sweet Journey
- hdu 5477 A Sweet Journey
- HDU 5477A Sweet Journey网赛
- hdu(5477)——A Sweet Journey
- hdu 5477 A Sweet Journey(水)
- HDU 杭电5477 A Sweet Journey
- hdu 5477 A Sweet Journey 模拟
- HDU 5477 A Sweet Journey 贪心 思维
- 【HDU】5477---A Sweet Journey(二分)
- hdoj 5477 A Sweet Journey
- HDU 5477 A Sweet Journey(亚洲区水题)
- 常用的C++11特性(面试易考)
- pgbouncer连接greenplum单机
- Android端运行Tensorflow的demo去分类自己的数据集
- Java回炉重造(三)使用Apache Commons Text库计算文本相似性:jaccard相似系数、余弦相似度
- hdoj1053 Entropy(哈夫曼编码)
- 0526 HDU#5477&G2n#A-A Sweet Journey
- C语言课设总结
- ASP.NET 5个著名内容管理系统CMS
- 51Nod--1004 n^n的末位数字
- JavaWeb开发知识总结(网上商城项目总结)
- Nginx expires缓存
- WEB请求过程
- Eigen 基本类型的使用
- 根据事件类型做出反应