0526 HDU#5477&G2n#A-A Sweet Journey
2017-06-02 23:18
134 查看
摘要:
按照一定的消耗方式,如何最少的使用能量。
原题目链接: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)
InputIn the first line there is an integer t (1≤t≤501≤t≤50),
indicating the number of test cases.
For each test case:
The first line contains four integers, n, A, B, L.
Next n lines, each line contains two integers: Li,RiLi,Ri,
which represents the interval [Li,Ri][Li,Ri] is
swamp.
1≤n≤100,1≤L≤105,1≤A≤10,1≤B≤10,1≤Li<Ri≤L1≤n≤100,1≤L≤105,1≤A≤10,1≤B≤10,1≤Li<Ri≤L.
Make sure intervals are not overlapped which means Ri<Li+1Ri<Li+1 for
each i (1≤i<n1≤i<n).
Others are all flats except the swamps.
OutputFor each text case:
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.
Sample Input
Sample Output
题目认识:
假定开始时已经是恰好最优状态 并设为状态0,依照消耗方式进行模拟。最后看状态的值是多少即可确定开始时的最低是多少。
注意:
计算需要补给的是多少。其他的不用改变状态值。
日期:
2017 5 26
代码:
按照一定的消耗方式,如何最少的使用能量。
原题目链接: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)
InputIn the first line there is an integer t (1≤t≤501≤t≤50),
indicating the number of test cases.
For each test case:
The first line contains four integers, n, A, B, L.
Next n lines, each line contains two integers: Li,RiLi,Ri,
which represents the interval [Li,Ri][Li,Ri] is
swamp.
1≤n≤100,1≤L≤105,1≤A≤10,1≤B≤10,1≤Li<Ri≤L1≤n≤100,1≤L≤105,1≤A≤10,1≤B≤10,1≤Li<Ri≤L.
Make sure intervals are not overlapped which means Ri<Li+1Ri<Li+1 for
each i (1≤i<n1≤i<n).
Others are all flats except the swamps.
OutputFor each text case:
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.
Sample Input
1 2 2 2 5 1 2 3 4
Sample Output
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;
}
相关文章推荐
- EXCEL数据处理、分析神器汇总0526
- HDU 5477 A Sweet Journey
- HDU 5477 A Sweet Journey 贪心 思维
- 【swift】15-0526 标签,函数
- A Sweet Journey
- 【HDU】5477---A Sweet Journey(二分)
- Mark-遇到的问题2015-0526(intent、fragment)
- HDU 5477 A Sweet Journey(亚洲区水题)
- HDU-5477-A Sweet Journey(简单模拟)
- 0526
- hdoj 5477 A Sweet Journey (二分查找)
- 2015 ACM/ICPC Asia Regional Shanghai Online-1010-A Sweet Journey
- 0526 《构建之法》第8-10章读后感
- A Sweet Journey
- 练习-----部门内部留言板(0526)
- 2015亚洲网络赛上海站1010A Sweet Journey
- ACM--过沼泽--模拟--HDOJ 5477--A Sweet Journey
- HDU 5477 A Sweet Journey(本场的最水题,过程处理好是关键)——2015 ACM/ICPC Asia Regional Shanghai Online
- 【杭电oj】5477 - A Sweet Journey(水)
- hdu5477 A Sweet Journey(简单模拟)