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 != ...
随机推荐
- 转:python webdriver API 之 获取对象的属性
获取测试对象的属性能够帮我们更好的进行对象的定位.比如页面上有很多标签为 input 元素,而我们需要定位其中 1 个有具有 data-node 属性不一样的元素.由于 webdriver 是不支持直 ...
- eclipse中修改maven仓储
1.找到maven的setting文件,修改setting文件: 2.打开eclipce,window->Preference->maven->user Setting
- run()和star()区别
run()和star()区别 run()-->只是thread类的一个普通方法调用 star()-->用来启动线程,实现多线程运行
- php第三方登陆
学习之前,请大家先看一下oAuth协议. 首先呢,我们进入QQ互联的官方网站 http://connect.qq.com登入我们自己的QQ号,没有QQ号的小伙伴可以忽略本篇博文分享!
- Codeforces Round #312 (Div. 2) E. A Simple Task
题目大意就是给一个字符串,然后多个操作,每次操作可以把每一段区间的字符进行升序或者降序排序,问最终的字符串是多少. 一开始只考虑字符串中字符'a'的情况,假设操作区间[L,R]中有x个'a',那么一次 ...
- JSP里比对单选框或复选框的数值而自动打勾
<table> <tr> <td class="tableleft">状态</td> <td><input typ ...
- paper 81:HDR成像技术
什么是HDR?谈HDR照片的制作方法和效果 HDR,是英文High-Dynamic Range的缩写,意为“高动态范围”.这是一个简单的术语,HDR照片是使用多张不同曝光的图片,然后再用软件将其叠加合 ...
- Linux mail 命令参数
linux mail 命令参数: 使用mail发邮件时,必须先将sendmail服务启动. mail –s “邮件主题” –c”抄送地址” –b “密送地址” -- -f 发送人邮件地址 –F 发件人 ...
- Android—监听器
网上有很多短信和电话监听的程序,使用Broadcast. 记得一年前自己对照视频和教材是能够实现的,这周打开视频和教材照猫画虎,无论怎么都不会,纠结啊! 问题原因: 3.0之后没有主动开启过的应用无法 ...
- 【cruch bang】中切换成左手鼠标
在“右键”菜单->settings->Edit autostart启动的geany编辑器中,最后加内容: xmodmap -e 'pointer = 3 2 1'