【链接】: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 5 7/2=3
7%2=1 8 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
*/

CF 990A. Commentary Boxes【数学/模拟】的更多相关文章

  1. CF 450E Jzzhu and Apples 数学+模拟

    E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. HDU 5810 Balls and Boxes 数学

    Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  3. C. Okabe and Boxes 思维 模拟 or 线段树

    C. Okabe and Boxes 这个题目是一个有点思维的模拟,当时没有想到, 思维就是这个栈的排序这里,因为每次直接排序肯定会t的,所以不可以这么写,那怎么表示排序呢? 就是直接把栈清空,如果栈 ...

  4. 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】

    Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  5. CF GukiZ hates Boxes 【二分+贪心】

    Professor GukiZ is concerned about making his way to school, because massive piles of boxes are bloc ...

  6. CF 999B. Reversing Encryption【模拟/string reverse】

    [链接]:CF [代码]: #include<bits/stdc++.h> #define PI acos(-1.0) #define pb push_back #define F fir ...

  7. zzulioj--1825-- 会长爱数学(模拟)

    1825: 会长爱数学 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 6  Solved: 2 SubmitStatusWeb Board Descr ...

  8. CF #366 DIV2 C. Thor 模拟 queue/stack降低复杂度

    C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  9. 北京网络赛G BOXES 大模拟+BFS

    题目描述 Description There is a strange storehouse in PKU. In this storehouse there are n slots for boxe ...

随机推荐

  1. 用伪类实现一个div的宽度和高度是固定百分比

    遇到一个题目:一个div宽度是固定百分比的情况下,如何设置高度是宽度的80% 看到题目的第一反应是用js控制,获取到div的宽度之后再用宽度的80%来设置div的高度,但是如何在不用js的情况下,只用 ...

  2. Bash 实例,第一部分

    您可能要问:为什么要学习 Bash 编程?好,以下是几条令人信服的理由: 已经在运行它 如果查看一下,可能会发现:您现在正在运行 bash.因为 bash 是标准 Linux shell,并用于各种目 ...

  3. 调用webservice接口

    这里是cxf服务器,采用myeclipse6.5,把wsdl放到本地的方式. 新建一个包, 把解析到的类放在这个包下面. 生成的代码结构: 调用: public static String callI ...

  4. JS遮罩层弹框效果

    对于前端开发者来说,js是不可缺少的语言.现在我开始把我日常积累的一些js效果或者通过搜索自己总结的一些效果分享给大家,希望能够帮助大家一起进步,也希望大家能够多多支持! 1.今天我先分享一个遮罩层弹 ...

  5. Go 实现 soundex 算法

    [转]http://www.syyong.com/Go/Go-implements-the-soundex-algorithm.html SOUNDEX 返回由四个字符组成的代码 (SOUNDEX) ...

  6. Linux emacs考场配置及对拍脚本

    emacs配置(待补) (global-set-key [f9] 'compile) (global-set-key [f10] 'gud-gdb) (global-set-ket (kbd &quo ...

  7. mysql 表的类型

    MySQL 数据表主要支持六种类型 ,分别是:BDB.HEAP.ISAM.MERGE.MYISAM.InnoBDB. 这六种又分为两类,一类是”事务安全型”(transaction-safe),包括B ...

  8. boost::bind的简单实现

    前言 在上一篇blog中简单的实现了boost::function,支持带有2个参数的函数/函数指针,函数对象,函数适配器/bind类,以及带有1个参数的成员函数指针. 本文接着来介绍如何实现一个简单 ...

  9. centos7安装tengine强制使用HTTPS访问

    操作系统:centos7.2 x64tengine:Tengine/2.2.0主机IP: 10.0.0.12 一.安装tengine 1.1 下载源码安装包 1.1.1 源码包pcre-8.40   ...

  10. java使用maven项目(二)分模块开发

    1       整合ssh框架 1.1     依赖传递 只添加了一个struts2-core依赖,发现项目中出现了很多jar, 这种情况 叫 依赖传递 1.2     依赖版本冲突的解决 1.  第 ...