hdu 5477 A Sweet Journey 模拟
来源:互联网 发布:软件项目管理ppt 编辑:程序博客网 时间:2024/05/16 16:10
A Sweet Journey
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1070 Accepted Submission(s): 539
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 meansRi<Li+1 for each i (1≤i<n ).
Others are all flats except the swamps.
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.
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.
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
12 2 2 51 23 4
Sample Output
Case #1: 0
Source
2015 ACM/ICPC Asia Regional Shanghai Online
Recommend
hujie | We have carefully selected several similar problems for you: 5932 5931 5930 5929 5928
题意:一段长为L的路上有沼泽和平地,平地上每行驶单位路程恢复B点能量,沼泽上则减少A点能量。问一开始最少需要准备多少能量。
解法:关键是使得行驶到沼泽右端点时的能量大于等于0即可。于是假设一开始有0点能量,能量为负仍然可以前进。现在模拟,找到能量的最低值minE,如果>=0,那么一开始不需要准备能量,否则准备-minE点。
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;const int INF =0x3f3f3f3f;int n,A,B,L;int main(){ std::ios::sync_with_stdio(false); int T,le,ri,kase=0;cin>>T; while(T--) { cin>>n>>A>>B>>L; int p=0,e=0,mine=INF; for(int i=1;i<=n;i++) { cin>>le>>ri; e+= B*(le-p)-A*(ri-le ); mine=min(mine,e); p=ri; } int ans=mine<0?-mine:0; printf("Case #%d: %d\n",++kase,ans); } return 0;}
0 0
- 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 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(二分)
- HDOJ5477 A Sweet Journey(模拟)
- HDU5477 A Sweet Journey 模拟
- hdu5477-模拟-A Sweet Journey
- 决策树学习
- Android自带的emoji表情的使用
- hibernate —— 双向多对一映射(增/删/改数据)
- JAVA 问题及解答
- Search a 2D Matrix II
- hdu 5477 A Sweet Journey 模拟
- git使用摘要
- iOS 通用赋值model类
- CodeBlocks安装及使用
- TOF相机-非扫描三维成像
- 如何写一个框架:步骤(上)
- hdoj 4990 Reading comprehension(矩阵快速幂)
- MFC中 'CString' to 'WPARAM'之间的转换
- Swift_继承