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 != ...
随机推荐
- CSS禅意花园(设计一)
设计 1.排版样式. 正文部分文字比例比菜单不分班的大,可区分着两个区域(说明正文比菜单重要).排版也是一种交流方式,运用文字的大小.间距.颜色调整样式,给浏览者丰富的信息. 2.图标 3.分割线 适 ...
- C#: 异步委托
http://www.cnblogs.com/yingzhongwen/p/4568350.html 讲了委托与事件,但是对异步委托研究得还不够深入. http://www.cnblogs.com/l ...
- Server.Transfer,Response.Redirect用法点睛
Server.Transfer,Response.Redirect的区别 如果你读过很多行业杂志和 ASP.NET 示例,你会发现,大多数人使用 Response.Redirect 将用户引导到另一个 ...
- 控件ListView
ListView的简单用法,先在布局文件中添加ListView控件: 接下来修改MainActivity中的代码: 由上面的代码可以知道,数据是无法直接传递给ListView的,需要借助适配器来完成. ...
- 验证你的邮箱是不是qq邮箱
Console.WriteLine("请输入你的qq邮箱"); string yx = Console.ReadLine(); int a = yx.LastIndexOf(&qu ...
- [CrunchBang]禁止“桌面上鼠标滚轮切换工作区桌面“
鼠标滚轮切换虚拟桌面相关问题, 编辑 ~/.config/openbox/rc.xml 在 <context name="Desktop">段: <mouse ...
- 【linux】暂时解决sis m672(神舟F4000 D9) linux驱动 宽屏分辨率的问题?
1. 首先安装包 sudo apt-get install gcc make binutils git xorg-dev mesa-common-dev libdrm-dev libtool buil ...
- JavaWeb开发实例---Servlet
1.页面转发:form表单的action属性值为Servlet类再web.xml中配置的URL. 2.重定向:sendRedirect() 只是 简单的页面跳转 转发:request.getRequ ...
- XP+devOps开发模式与scrum敏捷开发对比,docker虚拟化
XP+devOps开发模式与scrum敏捷开发对比,docker虚拟化 我们现在用的就是典型的XP+devOps模式,已经放弃scrum了 现在还很多公司弄docker虚拟化docker非常复杂,当然 ...
- c/c++ 常用的几个安全函数
_stprintf_s // 格式化字符串 _vsntprintf_s // 格式化 不定长参数用到