Round-number
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的更多相关文章
- POJ3252——Round Number(组合数学)
Round Numbers DescriptionThe cows, as you know, have no fingers or thumbs and thus are unable to pla ...
- POJ 3252 Round Number(数位DP)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6983 Accepted: 2384 Des ...
- 【BZOJ】【1662】/【POJ】【3252】 【USACO 2006 Nov】Round Number
数位DP 同上一题Windy数 预处理求个组合数 然后同样的方法,这次是记录一下0和1的个数然后搞搞 Orz cxlove /************************************* ...
- number.toFixed和Math.round与保留小数
如果你baidu/google过或者自己写过保留两位小数,那下面这代码一定不陌生 Math.round(number*100)/100 那你使用过Number.prototype.toFixed这个方 ...
- oracle的round函数和trunc函数
--Oracle trunc()函数的用法/**************日期********************/1.select trunc(sysdate) from dual --2013- ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- Oracle round函数是什么意思?怎么运用?
如何使用 Oracle Round 函数 (四舍五入) 描述 : 传回一个数值,该数值是按照指定的小数位元数进行四舍五入运算的结果. SELECT ROUND( number, [ decimal_p ...
- oracle round 函数,replace()函数
(1)如何使用 Oracle Round 函数 (四舍五入)描述 : 传回一个数值,该数值是按照指定的小数位元数进行四舍五入运算的结果.SELECT ROUND( number, [ decimal_ ...
- oracle 中的round()函数、null值,rownum
round()函数:四舍五入函数 传回一个数值,该数值按照指定精度进行四舍五入运算的结果. 语法:round(number[,decimals]) Number:待处理的函数 Decimals:精度, ...
- POJ 3252 Round Numbers
组合数学...(每做一题都是这么艰难) Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7607 A ...
随机推荐
- 大宇java面试系列(一):jvm垃圾回收
1. 说一下 JVM 有哪些垃圾回收算法? 标记-清除算法:标记无用对象,然后进行清除回收.缺点:效率不高,无法清除垃圾碎片. 标记-整理算法:标记无用对象,让所有存活的对象都向一端移动,然后直接清除 ...
- [剑指offer]删除链表中重复的结点(把重复的都删掉,1个不留)
①题目 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针. 例如,链表1->2->3->3->4->4->5 处理后为 ...
- 利用Xshell配置ssh免密码登录虚拟机,进行虚拟机与物理机的传输
先说一下 Xshell如何无密连接虚拟机: ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,这里介绍密钥认证方式登录到linux的方法.使用 ...
- nyoj 63-小猴子下落 (模拟)
63-小猴子下落 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:2 submit:5 题目描述: 有一颗二叉树,最大深度为D,且所有叶子的深度都相同 ...
- nyoj 455-黑色帽子
455-黑色帽子 内存限制:64MB 时间限制:1000ms 特判: No 通过数:4 提交数:7 难度:1 题目描述: 最近发现了一个搞笑的游戏,不过目前还没玩过.一个舞会上,每个人 ...
- 力扣(LeetCode)加一 个人题解
给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: 输入 ...
- PowerMock学习(六)之Mock Final的使用
Mock Final mockfinal相对来说就比较简单了,使用powermock来测试使用final修饰的method或class,比较简单,接口调用部分,还是service调用dao. 对于接口 ...
- 【绝对有收获】看看?必须告诉你为什么要使用MQ消息中间件(图解版)
欢迎关注文章系列 ,关注我 <提升能力,涨薪可待> <面试知识,工作可待> <实战演练,拒绝996> 也欢迎关注微信公众号[Ccww笔记],原创技术文章第一时间推出 ...
- element 根据某一个属性合并列
通过 span-method 绑定方法 objectSpanMethod方法 this.getSpanArr(this.tableData); //this.tableData 指接口取到的数据 // ...
- .NET高级特性-Emit(2.1)字段
在上篇blog写完的几天后,有读者反映写的过于复杂,导致无法有效的进行实践:博主在考虑到园子里程序员水平高低不一致的情况,所以打算放慢脚步,对类的一些内容进行详细的讲解,顺带的会写一些笔者所遇到过的E ...