HDU 5477 A Sweet Journey 水题

A Sweet Journey

Time Limit: 1 Sec  

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5477

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

HINT

 

题意

有一个人,走沼泽地会损失ai点能量,走正常的会得到bi点能量

然后问你一开始需要多少能量才行?

题解:

扫一遍就好了,签到题

代码:

//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100006
#define mod 1000000007
#define eps 1e-9
#define e exp(1.0)
#define PI acos(-1)
const double EP  = 1E-10 ;
int Num;
//const int inf=0x7fffffff;
const ll inf=999999999;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//*************************************************************************************

int a[maxn];
int main()
{
    int t=read();
    for(int cas=1;cas<=t;cas++)
    {
        int n=read(),A=read(),B=read(),l=read();
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++)
        {
            int L=read(),R=read();
            for(int j=L;j<R;j++)
            {
                a[j]=1;
            }
        }
        int temp = 0;
        int ans = 0;
        for(int i=0;i<l;i++)
        {
            if(a[i]==1)
            {
                if(temp<A)
                {
                    ans+=A-temp;
                    temp=0;
                }
                else temp=temp-A;
            }
            else
                temp+=B;
        }
        printf("Case #%d: %d\n",cas,ans);
    }
}

 

posted @ 2015-09-26 21:51  qscqesze  阅读(313)  评论(0编辑  收藏  举报