HDU - 5477 A Sweet Journey
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.
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.
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
Source
题意:要我们找需要消耗体力最多的那个地方(即你走一段沼泽,可能会体力为0,这就是你开头需要准备的体力。或是你上一段体力补充完了,这一段又被沼泽消耗光了体力,这也是要补充的体力)。读不懂题真要命
#include <cstdio> #include <iostream> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <map> using namespace std; #define ll long long const int maxn = 5100; int t, n, A, B, L, l, r; int main() { scanf("%d", &t); int miao = t; while(t--) { scanf("%d%d%d%d", &n, &A, &B, &L); int legacy = 0, position = 0, need = 0;//legacy是剩余耐力,need是需求,position是当前位置 for(int i = 0; i<n; i++) { scanf("%d%d", &l, &r); legacy += (l-position)*B-(r-l)*A;//(上一段平底回复的)-(这一段澡泽消耗的) position = r;//把上一段澡泽的最后一个位置标记下来 if(legacy<0)//耐力不够时需要额外添加 { need -= legacy;//这时候legacy是负的,所以要减 legacy = 0; } } printf("Case #%d: %d\n", miao-t, need); } return 0; }