uva 10673 Play with Floor and Ceil 数学
2016-04-22 09:28
190 查看
题目:
C - Play with Floor and CeilTime Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld
& %llu
x = p xk + q xk
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 nd integers p and q that satis es the given equation.
Input
The rst 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 youd 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,
p | x | and | q | x | ||
k | k |
Sample Input
3
5 2
40 2
24444 6
Sample Output
1 1
1 1
0 6
题目大意:
给x和k两个值求 p 和q两个整数使得x=p*x/k(下限)+q*x/k(上限)成立
题目思路:
做数学题要先化解,尽可能减少变量,否则直接暴力为o(n^2)
题目求解:
假设x/k(下限)为dx 上限为 ux
原式 x*k=p*dx+q*(dx+ux-dx)
x*k=(p+q)*dx+(ux-dx)*q
假设p+q==k
(x-dx)*k=(ux-dx)*q
化解为只有一个未知量
程序:
#include<iostream> #include<cstdio> using namespace std; int main() { int ci; scanf("%d",&ci); while(ci--) { long long int x,k,x_low,x_high; scanf("%lld%lld",&x,&k); x_low=x/k*k; x_high=(x/k+1)*k; int n=(x-x_low)*k/(x_high-x_low); printf("%d",k-n); printf(" %d\n",n); } return 0; }
相关文章推荐
- android paint 研究总结
- 自定义View实现图片缩放
- 在应用程序中播放音频和视频
- 翻译漫谈笔记之3翻译的步骤及其特点
- 如何自学Android
- AndroidSDK更新慢和Android Studio老连接不到外网的解决方式分享一下
- 剑指offer面试题 替换空格
- 堆内存传递
- 对称密钥与非对称密钥
- LLDB调试器
- figure元素
- plsql developer创建连接DBlinks
- C# 图片旋转360度程序
- UVA 1508 - Equipment 状态压缩 枚举子集 dfs
- Android之简单页面跳转
- 控制标签上移、下移、置顶、置底
- Oliver运维管理系统之三安装部署
- pageContext.request.contextPath
- Android中string.xml使用总结
- Smartcard