hdu4011 Working in Beijing

来源:互联网 发布:网络安全法宣传ppt 编辑:程序博客网 时间:2024/05/16 15:46
http://acm.hdu.edu.cn/showproblem.php?pid=4011

Working in Beijing

TimeLimit: 4000/2000 MS(Java/Others)    MemoryLimit: 65768/65768 K (Java/Others)
Total Submission(s):483    AcceptedSubmission(s): 256


Problem Description
Mr. M is an undergraduate student ofFDU. He finds an intern position in Beijing, so that he cannotattend all the college activities. But in some conditions, he mustcome back to Shanghai on certain date. We can assume the importantactivities that Mr. M must attend are occupy a whole day. Mr. Mmust take flight to Shanghai before that day and leave after thatday. On the other hand, Mr. M is absent in Beijing and he will losehis salary for his absent.
Sometimes the cost of flight is much higher than the loss ofsalary, so to save the cost on the travel, Mr. M can stay inShanghai to wait for another important date before he back toBeijing.
Now, Mr. M knows all of the important date in the next year. Helphim schedule his travel to optimize the cost.

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

Output
For each test case, output a singleinteger indicating the minimum cost for this year.
Sample Input
2 1 10 10 55 10 2 5 10 15 65 70
Sample Output
Case #1: 30Case #2: 74
Source
The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup


#include <iostream>
#include <stdio.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
const long  N=100010;
__int64 a[N],aa,minx;
int main()
{
    intn,t,b;
    inti,j,k;
     while (cin>>t)
     {
        minx=k=0;
        while (t--)
        {
          scanf("%d%I64d%d",&n,&aa,&b);
           minx=n*b+2*aa;//总共参加会议当天花费+往返费用(头尾)
          // printf("%I64d\n",minx);
           scanf("%I64d",&a[0]);
           for (i=1;i<n;i++)
           {
              scanf("%I64d",&a[i]);
              if(a[i]-1==a[i-1])continue;//连续两场会议,其实可以不用
              minx+=min((a[i]-a[i-1]-1)*b,2*aa);//留下来费用,往返机票费用,取较小着~
           }
           printf("Case #%d: %I64d\n",++k,minx);
          
        }
     }
return 0;
   
}
0 0