HDOJ题目地址:传送门

A Sweet Journey

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 759    Accepted Submission(s): 397
Problem Description
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≤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 , which represents the interval  [Li,Ri]  is swamp.
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  for each i ( 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

题意:一个人去旅行,路上有沼泽和平路,当走平路是增加a点体力,当走沼泽时消耗b点体力,求最开始最少要携带多少点体力

#include<iostream>
#include<stdio.h>
#include<memory.h>
#include<algorithm>
using namespace std;
struct Node{int begin;int end;int chazhi;
}zhaoze[101];
bool cmp(Node a,Node b){if(a.begin<b.begin)return true;return false;
}
int main(){int n,m,i,a,b,l,kaishi,jieshu,result,temp,index=1;cin>>n;while(n--){cin>>m>>a>>b>>l;for(i=0;i<m;i++){cin>>zhaoze[i].begin>>zhaoze[i].end;zhaoze[i].chazhi=zhaoze[i].end-zhaoze[i].begin;}sort(zhaoze,zhaoze+m,cmp);result=0;temp=0;kaishi=0;jieshu=0;for(i=0;i<m;i++){temp=temp+(zhaoze[i].begin-jieshu)*b-zhaoze[i].chazhi*a;jieshu=zhaoze[i].end;if(result>temp){result=temp;}}temp+=(l-jieshu)*b;if(result>temp){result=temp;}if(result<0){printf("Case #%d: %d\n",index,-result);}else{printf("Case #%d: 0\n",index);}index++;}
}

ACM--过沼泽--模拟--HDOJ 5477--A Sweet Journey相关推荐

  1. [2012山东ACM省赛] The Best Seat in ACM Contest (模拟)

    The Best Seat in ACM Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Cainiao is a ...

  2. 【HDU - 5477】A Sweet Journey(思维,水题)

    题干: Master Di plans to take his girlfriend for a travel by bike. Their journey, which can be seen as ...

  3. 著名的北邮ACM推荐50题

    著名的北邮ACM推荐50题 POJ推荐50题 1.标记"难"和"稍难"的题目可以看看,思考一下,不做要求,当然有能力的同学可以直接切掉. 2.标记为A and ...

  4. 50题(ACM学习推荐题)

    POJ推荐50题 1. 标记"难"和"稍难"的题目可以看看,思考一下,不做要求,当然有能力的同学可以直接切掉. 2. 标记为 A and B 的题目是比较相似的 ...

  5. Linux 常见问题 1000 个详细解答

    一. 如何建立多用户 提醒大家一句,别一直使用root用户,因为root用户在系统中有着至高无上的权力,一不小心就可能破坏系统.比如我们想删除/temp目录下的文件却将命令不小心输成"rm ...

  6. Linux 170个常见问题的详细解答

    Linux 170个常见问题的详细解答   <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:offi ...

  7. 国际计算机编程大赛报名,关于举办2020年新生编程大赛的报名通知

    各班级: 为了培养和发展大学生分析.解决问题和计算机编程的能力,鼓励和培养创新思维,丰富校园学术气氛,造就具有综合素质的面向21世纪的计算机科学人才,决定举办2020年新生编程大赛.现将有关事项通知如 ...

  8. 语法入门*算法入门题单

    作者:王清楚 链接:https://ac.nowcoder.com/discuss/817596?type=101&order=0&pos=1&page=4&chann ...

  9. java中如何输入字符

    char m = input.next().charAt(0); 下面是ACM中的模拟计算器的题目,以此作为示例: import java.util.*; public class Main { pu ...

最新文章

  1. 机器学习笔记:误差的来源(bias variance)
  2. RocketMQ的分布式事务解决方案
  3. 服务器修改数据库值,服务器上怎么修改数据库内存
  4. linux cpu softirq,linux softirq机制
  5. Mysql数据库常用命令,mysql速学实用教程。
  6. JavaScript文本特效实例小结【3个示例】
  7. 昔日最有前途的 Java 最终还是败给了晚辈 Python
  8. linux下好用的截图工具,Linux系统下一款比较易用的截图工具
  9. remapkey不能打开注册表_卸载 AutoCAD 清理注册表
  10. Python爬取国家税务总局纳税信用A级纳税人信息!
  11. MATLAB 使用GUI设计简单的计算器
  12. 关于macbookpro 外接显示器帧率问题
  13. Android app调用第三方地图(百度地图,高德地图,谷歌地图)导航
  14. 最好的跑步耳机推荐、盘点五款公认最好的跑步耳机
  15. 微信云函数的使用步骤
  16. 英语学习——学英语的心态(2)
  17. 台式计算机的主流配置,台式机主流配置型号参数
  18. “收藏本站” 的代码
  19. 哪些人工智能企业有内部人才培养项目?
  20. python需要购买版权吗_关于版权事宜的一些说明

热门文章

  1. WIN10 mscomm32注册,亲测可用
  2. 服务器开机后,自动启动某程序,并且打开Google浏览器,全屏展示
  3. JUC之striped64
  4. php date.getday,getDay()方法_用法示例-javascript词典-js编程词典-php中文网
  5. 计算机硬盘怎么看坏了,硬盘坏了怎么识别【如何修理】
  6. 微信小程序如何修改单页面背景色
  7. Quick BI企业报表制作——个人笔记
  8. Revit二次开发—载入族并交互式放置
  9. Vmware虚拟机怎么备份?2种简单方法!
  10. RGB与HSI的关系