【链接】:CF
【题意】:对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价。
【分析】:分情况讨论,自己多举几个栗子。
【代码】:

#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
using namespace std;typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const ll LNF = 1e18;
const int maxn = 1e3 + 100;
const int maxm = 100;
const double PI = acos(-1.0);
const double eps = 1e-8;
//const int dx[] = {-1,1,0,0,1,1,-1,-1};
//const int dy[] = {0,0,1,-1,1,-1,1,-1};
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
//        ио/ср/об/вС
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dir[6][3]={ {0,0,1},{0,0,-1},{-1,0,0},{1,0,0},{0,1,0},{0,-1,0} };
//int dir[4][2]= {{-1,0},{0,1},{1,0},{0,-1}};ll n,m;
ll a,b;
//对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价
int main()
{while(cin>>n>>m>>a>>b){ll ans;if(n%m==0){cout<<"0"<<endl;continue;}else{if(n>m){ans=min((n-m*(n/m))*b,(((n/m+1)*m-n)*a));}else ans=min(n*b,(m-n)*a);}cout<<ans<<endl;}
}
/*
9 7
9/7=1
9%7=2
↑↓
7-2*2*2=1
4 8 1 57/2=3
7%2=18 3 3 7
8/3=2
8%3=2
2*7=14↓
1*3=3↑9 6
6 6
12 6
9/6=1
9%6=3
*/

转载于:https://www.cnblogs.com/Roni-i/p/9212917.html

CF 990A. Commentary Boxes【数学/模拟】相关推荐

  1. Codeforces ~ 990A ~ Commentary Boxes (水)

    题意:你现在有 n n n个东西你要分给m" role="presentation">mmm个人,建造一个这个东西需要花费 a a a,毁坏一个这个东西需要花费b& ...

  2. JSK-337 汽水瓶【数学+模拟】

    汽水瓶 有这样一道智力题:"某商店规定:三个空汽水瓶可以换一瓶汽水.小张手上有十个空汽水瓶,她最多可以换多少瓶汽水喝?"答案是 5 瓶,方法如下:先用 9 个空瓶子换 3 瓶汽水, ...

  3. Codeforces A. Commentary Boxes

    A. Commentary Boxes 思路:直接比较 拆掉花费和修建划分 谁比较小. 代码: C++ 11 #include <iostream> #include <queue& ...

  4. 【CF#148B】Escape(模拟)

    题干: The princess is going to escape the dragon's cave, and she needs to plan it carefully. The princ ...

  5. CF #366(div.2) C 模拟,思维

    CF #366(div.2)  C.  Thor 题意:一个手机n个联系人,有q个操作.每次给出ty和ai,如ty==1,表示收到ai的一条信息:如ty==2,表示将ai发的信息都看掉:如ty==3, ...

  6. CF #499 div2 C. Fly(模拟)

    output standard output Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the ...

  7. CF - 379A. New Year Candles - 模拟

    1.题目描述: A. New Year Candles time limit per test 1 second memory limit per test 256 megabytes input s ...

  8. 【CF#2A】Winner(模拟 STL-map)☆

    题干: The winner of the card game popular in Berland "Berlogging" is determined according to ...

  9. CF - 794B. Cutting Carrot - 数学

    1.题目描述: B. Cutting Carrot time limit per test 2 seconds memory limit per test 256 megabytes input st ...

最新文章

  1. ios 调试的相关内容收集
  2. 子类继承父类,并重写父类方法
  3. Linux PF_INET6 定义
  4. 进一步考察与UI相关的安全漏洞-下
  5. 商品审核网页界面_商品模块数据库表解析(二)
  6. 活动执行手册_1-200家门店,标准化不等于手册!而是标准+训练+督导,缺一不可!...
  7. RAC OEM 打开无法显示CPU情况 的解决过程
  8. 终于有人把可解释机器学习讲明白了
  9. 【IOS下载】Cisco IOS下载
  10. django migrate 抛出异常:ValueError: Found wrong number (0) of constraints for …
  11. 从四大造字法看文字所承载的文化_对央视“汉字的魅力”讲授之管见(《天津教育报》2012年6月15日)...
  12. A[1054] The Dominant Colour (map!!)
  13. 交换机芯片技术知多少
  14. python自动聊天机器人_Python实现微信聊天机器人
  15. 【Linux实验】LINUX系统的文件操作命令
  16. Linux 进程之如何查看进程详情?
  17. 关于结构方程模型SEM评价指标
  18. 限界上下文(BC)是什么
  19. 台湾半导体制造商台积电市值首次超越英特尔
  20. Java中如果被除数是零时的异常处理

热门文章

  1. 1.字母异位词分组(LeetCode第49题)
  2. 图像去噪--Noise2Noise: Learning Image Restoration without Clean Data
  3. jekyll静态博客提升访问速度:内嵌CSS,异步加载js,压缩HTML
  4. LeetCode 829. Consecutive Numbers Sum--笔试题--C++解法
  5. ClickHouse系列教程三:MergeTree引擎分析
  6. java猜拳_求一个java猜拳游戏程序
  7. tomcat9配置https-pfx
  8. C++_泛型编程与标准库(八)
  9. 【Zookeeper进阶】大白话解释Zookeeper的选举机制
  10. 用python+pillow模块实现抖音晃眼睛的特效,图像处理之路(附源码)