题干:

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 (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.

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

题目大意:

Mr.D 带着他的女朋友出去旅行,资金缺乏,就骑着自行车出发了!路途中会遇到沼泽地和平坦路。每在沼泽地骑行一米,Mr.D能量值减少a,每在平坦大路上骑行一米就恢复能量值b。为了能成功到达目的地,在出发前至少需补充多少能量。

解题报告:

跟之前做过的一个机器人的差不多,数形结合一下,横轴是到原点的距离,纵轴是能量变化,先假设原点的能量是0,最后输出图像的最低点就可以了。

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cctype>
using namespace std;
typedef long long ll;
const int maxn=1e4+5;
int n,L,a,b;
int l[maxn],r[maxn];
int main()
{int t,i,j,k,cnt=0,nf;ll sum,ans;cin>>t;r[0]=0;for(;t;t--){scanf("%d%d%d%d",&n,&a,&b,&L); sum=ans=nf=0;if(nf) continue;for(i=1;i<=n;i++){scanf("%d%d",l+i,r+i);sum+=1LL*(l[i]-r[i-1])*b;sum-=1LL*(r[i]-l[i])*a;if(sum<0) {ans+=-sum;sum=0;}}printf("Case #%d: %lld\n",++cnt,ans);}return 0;
}

【HDU - 5477】A Sweet Journey(思维,水题)相关推荐

  1. codeforces 1060a(思维水题)

    Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", ...

  2. FZU 2230 2230 翻翻棋(思维水题)

    Problem Description 象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将.根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃掉对方的棋 ...

  3. CF Round #426 (Div. 2) The Useless Toy 思维 水题

    题目链接: http://codeforces.com/contest/834/problem/A 题目描述: 输入起始状态和结束状态和数列长度, 判断旋转方向是顺时针逆时针还是不合理 解题思路: 长 ...

  4. hdu 2025:查找最大元素(水题,顺序查找)

    查找最大元素 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  5. HDU 6168 Numbers 思维 水题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6168 题目描述: 定义数组b是由数组a每两项的和组成的,现在将数组A, B混在一起给你, 筛出数组A ...

  6. 中石油训练赛 - 姓氏(思维+水题)

    题目描述 在一个很大的课室里,里面有很多学生在听课.L老师挑选了其中的N个不同的学生起立回答问题,L老师对起立的每一个学生都是问同样的问题:"在本课室里,和你同姓的学生有多少人(不包括你自己 ...

  7. hdu 2275 Kiki Little Kiki 1 水题

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2275 这个题比较简单,所以就没有测试样例提供给大家,基本把题目的样例过了就可以了 题目大意 给你一串操作, ...

  8. HDU 5427 A problem of sorting 水题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5427 A problem of sorting Time Limit: 2000/1000 MS ( ...

  9. 【CodeForces - 707B】Bakery(思维水题)

    Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同 ...

  10. hdu 1117 Booklet Printing(模拟 分类 水题)

    传送门 http://acm.hdu.edu.cn/showproblem.php?pid=1117 首先上图, 这表示三张纸订正一本册子的姿势,是一张夹着一张的,明白了这个,就可以水过去了. 这里第 ...

最新文章

  1. Python装饰器是什么?使用Python装饰器实现计算程序(函数)运行时间的功能
  2. php sql oracle数据库,PHP、PLSQL连接oracle数据库的方法
  3. 老男孩最近几年常用的免费的开源软件
  4. Qt学习笔记-简单的TCP程序
  5. Lambda、函数式接口、Stream 一次性全给你
  6. PRML第十章 Approximate Inference(近似推断,变分推断,KL散度,平均场, Mean Field )
  7. redis cluster(5)- redis集群原理
  8. 关于需求跟踪矩阵的6个问题
  9. python卡方检验kf_Python 卡方检验
  10. 常见的安全产品与服务整理
  11. python“渡劫”进阶期(继承、多态、私有化、异常捕获、类属性和类方法)
  12. java编写一个可切换的界面_java web 项目实现手动中英文切换
  13. SONET/SDH概述
  14. word标题前自动分页
  15. 高数_向量代数_单位向量_向量与坐标轴的夹角
  16. HACCP原理——确定关键控制点(转载)
  17. 穿越之我是码农 1024 篇
  18. Sicily 1466. Taunt Exposure Estimation
  19. PL/SQL 九九乘法表
  20. 阿里云弹性公网EIP收费价格表(按量/包年包月/配置费)

热门文章

  1. 1048. Longest String Chain
  2. Linux启动过程以及初始化
  3. HDOJ-1257 最少拦截系统
  4. python总结字典集合列表_python 列表,元组,字典,集合,字符串相互转换
  5. jdbctemplate 开启事务_SpringBoot 系列教程之事务隔离级别知识点小结
  6. vuex的命名空间有哪些_Vue 3 带来的 Vuex 的替代方案
  7. uni app 调用网络打印机_uni-app 的使用体验总结
  8. python问号表达式_python中的问号表达式
  9. 环形队列出队的元素怎么输出出来_队列:队列在线程池等有限资源池中的应用...
  10. 深入浅出FSUIPC的作用以及使用方法