uva 10673 Play with Floor and Ceil
Problem A
Play with Floor and Ceil
Input: standard input
Output: standard output
Time Limit: 1 second
Theorem
For any two integers x and k there exists two more integers p and q such that:
It’s a fairly easy task to prove this theorem, so we’d not ask you to do that. We’d ask for something even easier! Given the values of x and k, you’d only need to find integers p and q that satisfies the given equation.
Input
The first line of the input contains an integer, T (1≤T≤1000) that gives you the number of test cases. In each of the following T lines you’d be given two positive integers x and k. You can safely assume that x and k will always be less than 108.
Output
For each of the test cases print two integers: p and q in one line. These two integers are to be separated by a single space. If there are multiple pairs of p and q that satisfy the equation, any one would do. But to help us keep our task simple, please make sure that the values, and fit in a 64 bit signed integer.
Sample Input Output for Sample Input
3 5 2 40 2 24444 6 |
1 1 1 1 0 6 |
Problem setter: Monirul Hasan, Member of Elite Problemsetters' Panel
Special Thanks: Shahriar Manzoor, Member of Elite Problemsetters' Panel
知道floor和ceil 就行。
floor向下取整 floor(1.9999) = 1;
同理。
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
typedef long long LL; LL Ex_GCD(LL a,LL b,LL &x,LL& y)
{
if(b==)
{
x=;
y=;
return a;
}
LL g=Ex_GCD(b,a%b,x,y);
LL hxl=x-(a/b)*y;
x=y;
y=hxl;
return g;
}
int main()
{
LL T;
LL a,b,c,g,x,y,n,m;
scanf("%d",&T);
while(T--)
{
scanf("%lld %lld",&n,&m);
a = (LL)floor(n/(double)m);/**向下取整floor(1.999) = 1 **/
b = (LL)ceil(n/(double)m);
c = n;
g = Ex_GCD(a,b,x,y); x=x*(c/g);
b=b/g;
x=x%b;
while(x<) x=x+b;
c=c/g;
y=(c-x*a)/b;
printf("%lld %lld\n",x,y);
}
return ;
}
uva 10673 Play with Floor and Ceil的更多相关文章
- php四舍五入函数(floor、ceil、round与intval)
原文链接:php四舍五入函数(floor.ceil.round与intval) PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言.语法 ...
- Number(),parseInt(),parseFloat(),Math.round(),Math.floor(),Math.ceil()对比横评
首先,这些处理方法可分为三类. 1,只用来处理数字取整问题的:Math.round(),Math.floor(),Math.ceil(): 2,专门用于把字符串转化成数值:parseInt(),par ...
- POJ1061:青蛙的约会+POJ2115C Looooops+UVA10673Play with Floor and Ceil(扩展欧几里得)
http://poj.org/problem?id=1061 第一遍的写法: #include <iostream> #include <stdio.h> #include & ...
- Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明
Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明 FLOOR——对给定的数字取整数位SQL> select floor(2345.67) from dua ...
- 问题:oracle floor;结果:Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明
Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明 (2011-04-06 16:10:35) 转载▼ 标签: 谈 分类: 渐行渐远 FLOOR——对给定的数字取 ...
- Play with Floor and Ceil UVA - 10673(拓展欧几里得)
因为我现在还不会用这个...emm...蒟蒻...只看了 从来没用过....所以切一道水题...练一下... 人家讲的很好 https://blog.csdn.net/u012860428/arti ...
- Java Math floor round ceil 函数
public final class Math extends Object public static double floor(double a) public static long round ...
- JavaScript中Math--random()/floor()/round()/ceil()
Math.random():返回0-1之间的任意数,不包括0和1: Math.floor(num):返回小于等于num的整数,相当于四舍五入的四舍,不五入:例子:Math.floor(1.0);Mat ...
- 关于Math类的round、floor、ceil三个方法
一.Math类这三个方法的简介 1.round():取最接近的值. 对于这个方法,查看源代码,其实现如下: public static long round(double a) { if (a != ...
随机推荐
- "数学口袋精灵"bug的发现及单元测试
1.项目内容: 团队项目:二次开发 至此,我们有了初步的与人合作经验,接下来投入到更大的团队中去. 也具备了一定的个人能力,能将自己的代码进行测试.接下来尝试在别人已有的基础上进行开发. 上一界51冯 ...
- 反射认识_03_改变成员变量Fields
包01:package ReflectionChange; public class ReflectionPoint_AB { String str1="access"; Stri ...
- Android异步任务AsyncTask
package com.example.asynctask; import java.net.MalformedURLException; import java.net.URL; import an ...
- java数组转化成集合
package com.shb.web; import java.util.Arrays;import java.util.List; import com.sun.xml.internal.ws.u ...
- springmvc转发与重定向
摘自http://elf8848.iteye.com/blog/875830 (1)我在后台一个controller跳转到另一个controller,为什么有这种需求呢,是这样的.我有一个列表页面,然 ...
- ssh & display
在Windows下用ssh连接服务器的话putty是一个小巧而且实用的工具,如果想要图形界面,可以使用X工具配合putty. 或者直接使用xmanager enterprise,非 常方便. 如果在U ...
- DDR(一)
P-Bank:计算机早期的一个概念.目的:匹配内存芯片和CPU芯片的数据总线的宽度.方法:并联多个内存模块. L-Bank:对内部存储阵列的分割,避免寻址冲突,提高内存效率.通过ba信号选择bank, ...
- 编译php时出现xsl错误的解决方法
是因为系统没安装一个叫 libxslt-devel 的包, 安装上就好了. 附编译php时的常见错误: http://www.myhack58.com/Article/sort099/sort0102 ...
- 关于UIView(转)
曾经有人这么说过,在iphone里你看到的,摸到的,都是UIView,所以UIView在iphone开发里具有非常重要的作用.那么UIView我们到底知道多少呢.请看看下面的问题, 如果这些你都知道, ...
- STM32外部中断.
void EXTIX_Init(void){ EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructu ...