码迷,mamicode.com
首页 > 其他好文 > 详细

【CodeForces 990A】Commentary Boxes

时间:2018-06-30 23:00:02      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:http   ima   中文   nta   start   tps   get   tor   demo   

题目链接

luogu & CodeForces

 

题目描述

Berland Football Cup starts really soon! Commentators from all over the world come to the event.

Organizers have already built nn commentary boxes. mm regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.

If nn is not divisible by mm , it is impossible to distribute the boxes to the delegations at the moment.

Organizers can build a new commentary box paying aa burles and demolish a commentary box paying bb burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.

What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by mm )?

 

中文翻译(摘自洛谷)

对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价

输入:

n,m,a,b

输出:

最小的代价

感谢@zhaotiensn 提供翻译

 

 

解题思路

额,没啥说的。

枚举向上取还是向下取,比较一下就好了。

 

 

 

 

还有,别忘了long long!!!

 

代码

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5 int main(){
 6     long long n,m,a,b;
 7     cin>>n>>m>>a>>b;
 8     long long x=n/m;
 9     long long add=((x+1)*m-n)*a;
10     long long jian=(n-x*m)*b;
11     cout<<min(add,jian)<<endl;
12 }

 

【CodeForces 990A】Commentary Boxes

标签:http   ima   中文   nta   start   tps   get   tor   demo   

原文地址:https://www.cnblogs.com/Fang-Hao/p/9248815.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!