您的位置:首页 > 其它

HDU-5477-A Sweet Journey(简单模拟)

2018-02-08 22:08 459 查看
题目链接---HDU-A Sweet Journry

A Sweet Journey

                                                          Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
                                                          Total Submission(s): 117    Accepted Submission(s): 60
[align=left]Problem Description[/align]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) 


 [align=left]Input[/align]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.
 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.
 
[align=left]Sample Input[/align]
12 2 2 51 23 4 
[align=left]Sample Output[/align]
Case #1: 0 
[align=left]Source[/align]2015 ACM/ICPC Asia Regional Shanghai Online题意:Di骑自行车旅行,经过平地和沼泽,经过沼泽时要消耗A的体力,经过平地时可以恢复B的体力,求出发时Di最少体力多少才能经过整段路程。题解:该题可以直接进行简单模拟,先假设Di出发时的体力为0,求他所消耗的最大体力代码实现如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f
using namespace std;
int main()
{
int t;
cin>>t;
int k=1;
while(t--)
{
int n,a,b,l,R,L;
cin>>n>>a>>b>>l;
int sum=0,p=0,minx=INF;
for(int i=0;i<n;i++)
{
cin>>L>>R;
sum=sum+b*(L-p)-a*(R-L);
minx=min(minx,sum);//求消耗体力的最大值
p=R;
}
printf("Case #%d: ",k++);
if(minx<0)
cout<<-minx<<endl;
else
cout<<0<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: