博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CSUOJ 1040 Round-number
阅读量:6934 次
发布时间:2019-06-27

本文共 1277 字,大约阅读时间需要 4 分钟。

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 104 10

Sample Output

100

Hint

题意:给两个数n,m 找到一个最接近n的m的倍数
#include
#include
#include
#include
using namespace std;int main(){ int n, b; while (~scanf("%d%d", &n, &b)) { int i; for (i = 1;; i++) { if (n > b*i) continue; else break; } int ans = b*i,temp=b*(i-1); if (ans - n > n - temp) cout << temp << endl; else cout << ans << endl; }}/********************************************************************** Problem: 1040 User: leo6033 Language: C++ Result: AC Time:8 ms Memory:2024 kb**********************************************************************/

转载于:https://www.cnblogs.com/csu-lmw/p/9124442.html

你可能感兴趣的文章
15+ 提升技能的 jQuery 教程
查看>>
.NET的3C:CTS、CLS和CLR 以及 IL
查看>>
VS2010 ASP.NET MVC4 安装失败问题
查看>>
Cocos2d-X数据、动作、消息的基本操作
查看>>
顺序队列及其操作
查看>>
c++,不能声明为虚函数的函数
查看>>
了解了解一下SQLSERVER里的鬼影记录
查看>>
PHP5.4新特性(转)
查看>>
(八)适配器模式详解
查看>>
Android实现导航菜单随着ListView联动,当导航菜单遇到顶部菜单时停止在哪里,并且listview仍能滑动...
查看>>
Hopcroft-Karp算法模版
查看>>
【POJ】2828 Buy Tickets(线段树+特殊的技巧/splay)
查看>>
推荐ThinkJS
查看>>
javaScript事件(二)事件处理程序
查看>>
数据库——修改表信息(转)
查看>>
SQL 存储过程 解析XML
查看>>
Atitit.木马病毒自动启动-------------win7计划任务的管理
查看>>
Javascript学习总结三(Array对象的用法)
查看>>
hiho_1050_树中的最长路
查看>>
Centos6.5搭建java开发环境
查看>>