0526 HDU#5477&G2n#A-A Sweet Journey



摘要:
按照一定的消耗方式,如何最少的使用能量。
原题目链接:HDU - 5477
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) 


Input
In the first line there is an integer t ( 1t50 1≤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,Ri Li,Ri, which represents the interval  [Li,Ri] [Li,Ri] is swamp. 
1n100,1L105,1A10,1B101Li<RiL 1≤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+1 Ri<Li+1 for each i ( 1i<n 1≤i<n). 
Others are all flats except the swamps. 
Output
For 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

   
   
题目认识:
假定开始时已经是恰好最优状态 并设为状态0,依照消耗方式进行模拟。最后看状态的值是多少即可确定开始时的最低是多少。

注意:
计算需要补给的是多少。其他的不用改变状态值。

日期:
2017 5 26
代码:
   
   
  1. #include <cstdio>
  2. #include <algorithm>
  3. #define MAX 0
  4. int getans(){
  5. int n,A,B,L;
  6. int need=0,s=0;//strength
  7. int li,ri,lastRi=0;
  8. scanf("%d%d%d%d",&n,&A,&B,&L);
  9. while(n--){
  10. scanf("%d%d",&li,&ri);
  11. s+=B*(li-lastRi);
  12. s-=A*(ri-li);
  13. if(s<0){need+=s;s=0;}
  14. lastRi=ri;
  15. }
  16. return -need;
  17. }
  18. int main(){
  19. int t;
  20. scanf("%d",&t);
  21. for(int i=1;i<=t;i++){
  22. printf("Case #%d: %d\n",i,getans());
  23. }
  24. return 0;
  25. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值