hdu4011 Working in Beijing

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


#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;
     
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值