UVA10673 - Play with Floor and Ceil(数论)

题目链接

题目大意:给你x,k,要求你找出p,q:满足x = p?下取整(x/k)
+ q?上取整(x/k);

解题思路:分三种情况:1、x整除k,那么可以另p = 0,那么q = k。

2、x不整除k,那么另n=下取整(x/k),则x=p?n
+ q?(n
+ 1)= (p + q)*n + q;那么就可以让q = x%k。那么(p + q)= x/(x/k)。p = x/(x/k) - q;

3、x<k的情况。要单独处理不然会除到0.

代码:

#include <cstdio>
#include <cstring>

int main () {

    int T, X, K;
    scanf ("%d", &T);
    while (T--)  {

        scanf ("%d%d", &X, &K);
        if (X < K) {
            printf ("%d %d\n", 0, X);
            continue;
        }

        if (X % K == 0)
            printf ("0 %d\n", K);
        else {
            int q = X % (X / K);
            int p = X / (X / K) - q;
            printf ("%d %d\n", p, q);
        }
    }
    return 0;
}
时间: 2025-01-04 04:39:26

UVA10673 - Play with Floor and Ceil(数论)的相关文章

Uva10673 - Play with Floor and Ceil ( 扩展欧几里定理 )

Uva10673 - Play with Floor and Ceil ( 扩展欧几里定理 )  实际上是一道很裸的扩展欧几里德定理的题目,结果把Floor和Ceil搞反了WA一次悲剧啊 #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; typedef long long LL; void ex_gcd(LL a, L

UVA - 10673 - Play with Floor and Ceil (简单数学!)

题目链接:Play with Floor and Ceil UVA - 10673 Play with Floor and Ceil Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu SubmitStatus Description Problem A Play with Floor and Ceil Input: standard input Output: standard output Tim

问题:oracle floor;结果:Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明

Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明 (2011-04-06 16:10:35) 转载▼ 标签: 谈 分类: 渐行渐远 FLOOR——对给定的数字取整数位 SQL> select floor(2345.67) from dual; FLOOR(2345.67) -------------- 2345 CEIL-- 返回大于或等于给出数字的最小整数 SQL> select ceil(3.1415927) from dual; CEIL(3.14

Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明

Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明 FLOOR——对给定的数字取整数位SQL> select floor(2345.67) from dual; FLOOR(2345.67)--------------2345 CEIL-- 返回大于或等于给出数字的最小整数SQL> select ceil(3.1415927) from dual; CEIL(3.1415927)---------------              4 ROUND——按

UVa 10673 Play with Floor and Ceil

方法 : 数论? 用k,x/k, x%k表示 ceil 和 floor,观察求解. code: #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <string> #include <vector> #include <stack> #include <bitset> #include &

Uva 10673-Play with Floor and Ceil(扩展欧几里得)

题目链接:点击打开链接 题意:给出x, k 求 方程 p*floor(x/k)+q*ceil(x/k)=x的一个解.floor()为向上取整,ceil()为向下取整. 赤裸裸的扩展gcd,题目中没说无解的情况,应该是默认 x%gcd(floor(x/k),ceil(x/k))==0 对于扩展gcd,ax+by=d ① ,当d为g=gcd(a,b)的倍数时,方程①有解,转化为求 ax+by=g ②的解,假设求出来方程②的解为 (x0,y0) 方程②左右同乘 d/g,得 a*(x0*d/g)+b*(

php中round、floor、ceil的用法

round()对浮点数进行四舍五入 float round( float $val[,int $precision = 0[, int $mode = PHP_ROUND_HALF_UP]] ): 返回将 val 根据指定精度precision(十进制小数点后数字的数目)进行四舍五入的结果.precision也可以是负数或零默认值). floor()舍去法取整 float floor( float $value ): 返回不大于value 的最接近的整数,舍去小数部分取整. ceil()进一法取

JavaScript中Math--random()/floor()/round()/ceil()

Math.random():返回0-1之间的任意数,不包括0和1: Math.floor(num):返回小于等于num的整数,相当于四舍五入的四舍,不五入:例子:Math.floor(1.0);Math.floor(1.5);Math.floor(1.9);都返回1: Math.round(num):num进行四舍五入:例子:Math.round(1.0);Math.round(1.4);返回1;/Math.round(1.5);Math.round(1.9);返回2; Math.ceil(nu

floor() 和 ceil()函数

在C语言的库函数中,floor函数的语法例如以下: #include <math.h> double floor( double arg ); 功能: 函数返回參数不大于arg的最大整数.比如, x = 6.04; y = floor( x ); y的值为6.0. 与floor函数相应的是ceil函数,即上取整函数. 有趣的是,floor在英文中是地板的意思,而ceil是天花板的意思,非常形象地描写叙述了下取整和上取整的数学运算. 说明:假设任一參数为非数值參数,则 FLOOR 将返回错误值#