杭电4011 亚洲区域赛上海赛区网络热身赛

我是认为这道题挺难的,一直认为是dp的,,,没想到贪心也可以ac,,思想是差不多的,昨天我一直在想到底怎么写方程,今天还在想,,,终于还是没想出来。。。。太笨了,,,还是在别人的提示下才做出来,,,纠结。。。。。题目:

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
ac代码,,会超出整型范围,故sum要用_int64:
#include <iostream> #include <cstdio> using namespace std; int main() { int tt; scanf("%d",&tt); for(int i=1;i<=tt;++i) { int n,a,b,t[100005]; scanf("%d%d%d",&n,&a,&b); for(int ii=0;ii<n;++ii) scanf("%d",&t[ii]); _int64 sum=2*a+b; for(int j=1;j<n;++j) { sum+=b; sum+=min(2*a,(t[j]-t[j-1]-1)*b); } printf("Case #%d: %I64d\n",i,sum); } return 0; }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值