HDU-4011 Working in Beijing(题意理解)

Working in Beijing

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 2113    Accepted Submission(s): 901


 

Problem Description

Mr. M is an undergraduate student of FDU. He finds an intern position in Beijing, so that he cannot attend all the college activities. But in some conditions, he must come back to Shanghai on certain date. We can assume the important activities that Mr. M must attend are occupy a whole day. Mr. M must take flight to Shanghai before that day and leave after that day. On the other hand, Mr. M is absent in Beijing and he will lose his salary for his absent.
Sometimes the cost of flight is much higher than the loss of salary, so to save the cost on the travel, Mr. M can stay in Shanghai to wait for another important date before he back to Beijing.
Now, Mr. M knows all of the important date in the next year. Help him schedule his travel to optimize the cost.

 

 

Input

The input contains several test cases. The first line of single integer indicates the number of test cases.
  For each test case, the first line contains three integers: n, a and b, denoting the number of important events, the cost of a single flight from Beijing to Shanghai or Shanghai to Beijing and the salary for a single day stay in Beijing. (1 <= n <= 100000, 1 <= a <= 1000000000, 1 <= b <=100)
  Next line contains n integers ti, denoting the time of the important events. You can assume the ti are in increasing order and they are different from each other. (0 <= ti <= 10000000)

 

 

Output

For each test case, output a single integer indicating the minimum cost for this year.

 

 

Sample Input

 

2

1 10 10

5

5 10 2

5 10 15 65 70

 

 

Sample Output

 

Case #1: 30

Case #2: 74

 

 

Source

The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup

 

 

Recommend

lcy   |   We have carefully selected several similar problems for you:  4019 4012 4013 4014 4015 

 

读题理解题意花了很久...其实就很简单比较一下,我们居然想了很久!

【题意】 

输入n,a,b,n是放假天数(放假不扣钱),a:单程机票钱,b:旷工扣的工资钱

如果两个假期的间隔天数旷工扣的工资钱(b*间隔天数) < 先回去,再来的往返机票钱(2*a),那妥妥的不回去划算呀~~

所以比较下就好了,算下最小花费

【AC代码】

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define go(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
ll num[maxn];
int main()
{
    ll t,n,a,b,sum;
    scanf("%lld",&t);
    go(i,1,t)
    {
        sum = 0;
        scanf("%lld%lld%lld",&n,&a,&b);
        go(j,0,n-1) scanf("%lld",&num[j]);
        printf("Case #%d: ",i);
        sum += n * b + 2 * a;
        if(n >= 2)
        {
            go(j,1,n-1)
            {
                if((num[j] - num[j-1] - 1)*b <= (a*2))
                    sum += (num[j] - num[j-1] - 1)*b;
                else
                    sum += a*2;
            }
            printf("%lld\n",sum);
        }
        else
            printf("%lld\n",sum);
    }
    return 0;
}

 

你可能感兴趣的:(HDUOJ,比赛)