HDU-5477-A Sweet Journey(简单模拟)
2018-02-08 22:08
459 查看
题目链接---HDU-A Sweet Journry
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)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201802/634cc03ba8ae33090e63e17f99aa472d.jpg)
[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;
}
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)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201802/634cc03ba8ae33090e63e17f99aa472d.jpg)
[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;
}
相关文章推荐
- hdu 5477 A Sweet Journey 模拟
- POJ 1573 && hdu 1035 Robot Motion【简单模拟】
- HDU 1106 排序(简单分类模拟)
- HDU-1008-Elevator(Java版本+简单模拟+恶心水果)
- HDU 5477 A Sweet Journey 贪心 思维
- hdu 2093(简单模拟)
- hdu 5095 Linearization of the kernel functions in SVM (简单模拟)
- HDU 5477 A Sweet Journey(本场的最水题,过程处理好是关键)——2015 ACM/ICPC Asia Regional Shanghai Online
- HDU 5477 A Sweet Journey 水题
- ACM--过沼泽--模拟--HDOJ 5477--A Sweet Journey
- hdu 1210 简单数学模拟
- hdu 1683 Colour sequence(简单模拟)
- POJ 1573 && hdu 1035 Robot Motion(简单模拟)
- hdu 1062 Text Reverse(字符串处理,简单模拟)
- hdu 1228 A+B(简单模拟)
- 简单浮点数除法模拟-hdu-4493-Tutor
- POJ 1573 && hdu 1035 Robot Motion【简单模拟】
- 模拟_简单模拟处理边界(HDU_2525)
- HDU 5301 Souvenir(简单模拟)
- The calculation of GPA HDU - 1202(简单模拟)