Description

Most of the time when rounding a given number, it is customary to round to some multiple of a power of 10. However, there is no reason why we cannot use another multiple to do our rounding to. For example, you could round to the nearest multiple of 7, or the nearest multiple of 3.
    Given an int n and an int b, round n to the nearest value which is a multiple of b. If n is exactly halfway between two multiples of b, return the larger value.

Input

Each line has two numbers n and b,1<=n<=1000000,2<=b<=500

Output

The answer,a number per line.

Sample Input

5 10
4 10

Sample Output

10
0

Hint

#include<stdio.h>

int main()
{
int n,b;
while(scanf("%d%d",&n,&b)!=EOF)
{
int i=1;
while(n>b*i) i++;
int temp1=b*i;
int temp2=b*(i-1);
if(temp1-n>n-temp2)
printf("%d\n",temp2);
else
printf("%d\n",temp1);
}
return 0;
}
/**********************************************************************
Problem: 1040
User: song_hai_lei
Language: C++
Result: AC
Time:0 ms
Memory:1120 kb
**********************************************************************/

Round-number的更多相关文章

  1. POJ3252——Round Number(组合数学)

    Round Numbers DescriptionThe cows, as you know, have no fingers or thumbs and thus are unable to pla ...

  2. POJ 3252 Round Number(数位DP)

    Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6983   Accepted: 2384 Des ...

  3. 【BZOJ】【1662】/【POJ】【3252】 【USACO 2006 Nov】Round Number

    数位DP 同上一题Windy数 预处理求个组合数 然后同样的方法,这次是记录一下0和1的个数然后搞搞 Orz cxlove /************************************* ...

  4. number.toFixed和Math.round与保留小数

    如果你baidu/google过或者自己写过保留两位小数,那下面这代码一定不陌生 Math.round(number*100)/100 那你使用过Number.prototype.toFixed这个方 ...

  5. oracle的round函数和trunc函数

    --Oracle trunc()函数的用法/**************日期********************/1.select trunc(sysdate) from dual --2013- ...

  6. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

  7. Oracle round函数是什么意思?怎么运用?

    如何使用 Oracle Round 函数 (四舍五入) 描述 : 传回一个数值,该数值是按照指定的小数位元数进行四舍五入运算的结果. SELECT ROUND( number, [ decimal_p ...

  8. oracle round 函数,replace()函数

    (1)如何使用 Oracle Round 函数 (四舍五入)描述 : 传回一个数值,该数值是按照指定的小数位元数进行四舍五入运算的结果.SELECT ROUND( number, [ decimal_ ...

  9. oracle 中的round()函数、null值,rownum

    round()函数:四舍五入函数 传回一个数值,该数值按照指定精度进行四舍五入运算的结果. 语法:round(number[,decimals]) Number:待处理的函数 Decimals:精度, ...

  10. POJ 3252 Round Numbers

     组合数学...(每做一题都是这么艰难) Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7607 A ...

随机推荐

  1. Windows对python文件加密

    最近项目需要对部分python文件加密,调研了部分方法都觉得不可行,最后采用了将python转换成so文件.pyd文件的方法.so文件,为liunx下的动态链接库文件,在windows下为dll文件, ...

  2. 【Swift】UNNotificationServiceExtension

    一.简介 An object that modifies the content of a remote notification before it's delivered to the user. ...

  3. Unity 简记(1)--TileMap

    ## Tilemap是unity中自带的快速构建2D场景的工具,优点是省时省力, 1 使用方法 在场景创建一个Tilemap 打开TilePalette ​ 3.创建一个新的Palette,将地图切割 ...

  4. JSON数据与Java对象的相互转换

    JSON数据与Java对象的相互转换 JSON解析器 常见的解析器:Jsonlib .Gson. fastjson. jackson JSON转化为Java对象 使用步骤: 1.导入jackson的相 ...

  5. 014.Kubernetes二进制部署docker

    一 部署docker 1.1 部署docker组件 docker 运行和管理容器,kubelet 通过 Container Runtime Interface (CRI) 与它进行交互. 1.2 下载 ...

  6. [LC]111题 二叉树的最小深度 (递归)

    ①题目 给定一个二叉树,找出其最小深度. 最小深度是从根节点到最近叶子节点的最短路径上的节点数量. 说明: 叶子节点是指没有子节点的节点. 示例: 给定二叉树 [3,9,20,null,null,15 ...

  7. hdu 1509 Windows Message Queue (优先队列)

    Windows Message QueueTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  8. css3布局-圣杯布局

    圣杯布局he双飞翼布局都是解决两边固定款中间自适应的三栏布局 圣杯布局为了中间div内容不被别的内容覆盖,将中间div设置了左右的内边距后,将左右两个div用相对布局position: relativ ...

  9. Java——内部类详解

    说起内部类,大家肯定感觉熟悉又陌生,因为一定在很多框架源码中有看到别人使用过,但又感觉自己使用的比较少,今天我就带你具体来看看内部类. 内部类基础 所谓内部类就是在类的内部继续定义其他内部结构类. 在 ...

  10. 学习完vue指令 做的一个学生信息录入系统

    一.demo实现原理 输入完个人信息后  点击创建用户  数据就会显示在下面的表格中 用到了vue中的数据双向绑定 v-model v-for 还要js正则 数组的unshift splice 等方法 ...