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. jquery正确获取iframe里元素的方法

    <iframe id="_ae_frame" width="100%" height="100%" frameborder=" ...

  2. 如何查看当前linux服务器是否支持虚拟化

    [root@localhost ~]# grep -E '(svm|vmx)' /proc/cpuinfo 或者: [root@localhost ~]# cat /proc/cpuinfo 找到fl ...

  3. 自学python的高效学习方法【python秘籍】

    随着互联网的发展,数据科学概念的普及,Python火得一塌糊涂,为此很多小伙伴想学这门语言,苦于没有正确的学习方法,大部分都放弃了,所以我想总结下经验来帮助大家高效学完python技术!第一.首先学习 ...

  4. C#winfrom将XML数据保存读取删除

    //创建一个数据集,将其写入xml文件 string name = "1.xml"; System.Data.DataSet ds = new System.Data.DataSe ...

  5. Secure CRT注册码

    secure CRT 把记忆的东西放在这就行了,:)   SecureCRT 5.2.2的注册码 Name:          Apollo InteractiveCompany:    Apollo ...

  6. Anaconda 笔记

    Anaconda笔记 conda 功能 管理版本的切换 安装其他的包 conda 创建python27环境 conda create --name python27 python=2.7 conda ...

  7. 【python测试开发栈】带你彻底搞明白python3编码原理

    在之前的文章中,我们介绍过编码格式的发展史:[文章传送门-todo].今天我们通过几个例子,来彻底搞清楚python3中的编码格式原理,这样你之后写python脚本时碰到编码问题,才能有章可循. 我们 ...

  8. django_4数据库3——admin

    生成admin界面 1.setting.py中,保证'django.contrib.admin',应用打开,django1.11默认打开的 2.url.py中的admin默认时打开的 3.对model ...

  9. windows版的mysql主从复制环境搭建

    背景 最近在学习用Spring Aop来实现数据库读写分离的功能. 在编写代码之前,首先是要部署好mysql的环境,因为要实现读写分离,所以至少需要部署两个mysql实例,一主一从,并且主从实例之间能 ...

  10. HTML的footer置于页面最底部

    vue项目中,使用element-ui的布局,仍然出现footer不固定页面底部的情况,网上找到的一个管用的 方法是:footer高度固定+绝对定位 <html> <head> ...