hdu+4011

qq_46297150 2020-09-16 04:45:26
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 #include<iostream> using namespace std; int main(){ int t,d=1,m=1; cin>>t; while(t--){ int n,a,b,i,c=0,d1,d2; cin>>n>>a>>b; int w[100000]; for(i=0;i<n;i++) cin>>w[i]; c+=2*a+b; for(i=0;i<n-1;i++){ d1=(w[i+1]-w[i])*b; d2=2*a+b; if(d1>=d2) c+=d2; else c+=d1; } cout<<"Case #"<<m++<<": "<<c<<endl; } } 交上去wa了,不知道错在哪里,还是少考虑了,希望大佬指教
...全文
129 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_46297150 2020-09-17
  • 打赏
  • 举报
回复
引用 4 楼 qybao的回复:
[quote=引用 2 楼 qq_46297150 的回复:]
对于两个重要日子之间只有2种方案,选成本低的就行了吧,因为重要日子是必须在上海的吧,不用排列组合吧

直接选最优也可以,只是你的循环里样例数据之间没有把c初始化,c会一直累加,所以 c+=2*a+b 改成 c=2*a+b[/quote] 初始化了的,刚刚ac了,是c的类型错了,应该是long long
qybao 2020-09-17
  • 打赏
  • 举报
回复
引用 2 楼 qq_46297150 的回复:
对于两个重要日子之间只有2种方案,选成本低的就行了吧,因为重要日子是必须在上海的吧,不用排列组合吧

直接选最优也可以,只是你的循环里样例数据之间没有把c初始化,c会一直累加,所以 c+=2*a+b 改成 c=2*a+b
qq_46297150 2020-09-17
  • 打赏
  • 举报
回复
找到错了,应该用long long
qq_46297150 2020-09-16
  • 打赏
  • 举报
回复
引用 1 楼 qybao的回复:
这道题没那么简单,需要排列组合,从这些组合中求最优解。 比如某个重要日子可以选择返回北京或留在上海(2种选择),选择返回则花机票钱,选择留则扣工资。每个重要日子都有2种选择,每种选择就形成一个组合,计算该组合的成本,从这些成本种找出最小成本。
对于两个重要日子之间只有2种方案,选成本低的就行了吧,因为重要日子是必须在上海的吧,不用排列组合吧
qybao 2020-09-16
  • 打赏
  • 举报
回复
这道题没那么简单,需要排列组合,从这些组合中求最优解。 比如某个重要日子可以选择返回北京或留在上海(2种选择),选择返回则花机票钱,选择留则扣工资。每个重要日子都有2种选择,每种选择就形成一个组合,计算该组合的成本,从这些成本种找出最小成本。

64,683

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧