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 youd be given two positive integers x and k. You can safely assume that x and k will always be less than 10^8.
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,

fit in a 64 bit signed integer.
Sample Input
3
5 2
40 2
24444 6
Sample Output
1 1
1 1
0 6

问题链接:UVA10673 Play with Floor and Ceil
问题简述:(略)
问题分析
    查找满足题目中公式的p和q,枚举p(1-k),找到p和q则输出p和q。
    另外一种方法是经过推导得出p和q的一般式子进行计算。参见代码。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++程序如下:

/* UVA10673 Play with Floor and Ceil */#include <bits/stdc++.h>using namespace std;int main()
{int n, x, k;scanf("%d", &n);while (n--) {scanf("%d%d", &x, &k);printf("%d %d\n", k - x % k, x % k);}return 0;
}

AC的C++程序(枚举)如下:

/* UVA10673 Play with Floor and Ceil */#include <bits/stdc++.h>using namespace std;typedef long long LL;int main()
{int t;scanf("%d", &t);while(t--) {LL x, k;scanf("%lld %lld", &x, &k);LL p, q, fl = floor((double) x / k), ce = ceil((double) x / k);for(p = 0; p <= k; p++) {q = (x - p * fl) / ce;if(p * fl + q * ce == x)break;}printf("%d %d\n", p, q);}return 0;
}

UVA10673 Play with Floor and Ceil【暴力枚举】相关推荐

  1. YBTOJ:灯光控制(贪心)(公倍数)(暴力枚举)

    文章目录 题目描述 解析 代码 题目描述 解析 没有想出来 首先可以确定开关要么开一次,要么不动,其他都和这俩是等价的 一开始最先想到的就是贪心的方法,每个开关遍历,如果按下会使答案变好就按下. 但是 ...

  2. 2013数据结构课程设计之便利店选址(暴力枚举或随机函数或三分)

    [问题描述] 某小区决定在小区内部建一家便利店,现小区内部共有八栋楼,它们的地理坐标分别为:(10,20) (30,34) (19,25) (38,49.1) (9,38.1) (2,34) (5,8 ...

  3. POJ 3174 暴力枚举

    思路: 暴力枚举三个点 判一判 搞定 (x1*y1=x2*y2) x1.y1.x2.y2为他们两两的差 //By SiriusRen #include <cstdio> using nam ...

  4. codeforces数学1600day6[CodeForces - 1029C多区间交+枚举,CodeForces 992C[数学公式推导],CodeForces 992B[质因数分解+暴力枚举]]

    A - Maximal Intersection CodeForces - 1029C 题目大意:就是给你n个区间,这n个区间有公共的区间长度为x,现在叫你从这n个区间中删掉一个使得x最大化. 解题思 ...

  5. 最大字段和 冲出暴力枚举

    这篇解题报告是对我最近一些题的总结,里面的代码都是我解题,优化,再优化的过程的记录,记录了自己对算法的完善与优化思路,还有对编程哲学的理解:do it,do it well. 很感谢孙老师您,让自己可 ...

  6. hdu 4587 TWO NODES 暴力枚举+tarjan

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意是拿掉两个点 求最多可以把整个图分成几个联通块 注意到有一个模板是可以通过找割点来快速求出 ...

  7. 一道暴力枚举题Win32版本示例

    来看一个问题:该问题的解法是 暴力枚举:这大概是ACM方面的:名称叫火柴棒等式: 给你n根火柴棍,你可以拼出多少个形如"A+B=C"的等式?等式中的A.B.C是用火柴棍拼出的整数( ...

  8. C. Divisibility by Eight【暴力枚举】

    暴力枚举即可.枚举1位这种情况,枚举2位这种情况,枚举3位这种情况. 3位满足足以,其他的4位,5位...都包含1000必定满足. #include<bits/stdc++.h> usin ...

  9. array专题2---理解暴力枚举与动态规划

    746 Min Cost Climbing Stairs 一直以后对暴力枚举(又称:深度优先搜索)和动态规划不太理解,不能明白个中区别,更别说贪心.今天做这道题目的时候有点心得. 思路一:看到题目,直 ...

最新文章

  1. 服务器ldap认证配置
  2. 把时间当作朋友(第一版)笔记
  3. 计算机基础18春在线作业1,东师-计算机应用基础18春在线作业1-1.docx
  4. 7月24日 学习笔记
  5. 安装android sdk,后出现导出错误,提示命令行找不到解决方案
  6. LeetCode 1000. 合并石头的最低成本(区间DP)
  7. cf不能全屏win7的解决方法_win7系统局域网不能访问怎么办 win7局域网不能访问解决方法...
  8. mysql中对比月_详解Mysql中日期比较大小的方法
  9. 大三软件工程小项目-小技术集合-Qt状态栏设置
  10. IoT开发精英实战营招募啦!速来报名!
  11. ice 服务java连接,java - ICE中的连接计数 - 堆栈内存溢出
  12. Java对Map排序
  13. 工业互联网平台基本架构
  14. 华旭 身份证读卡器测试软件_华旭HX-FDX3S读卡器驱动+身份证验证软件
  15. maven打包的时候同时打源码包,并同时将源码包上传私服
  16. 微信公众号关注自动回复内容php ci,如何实现微信公众号“一键关注”功能?运营神器...
  17. 企业邮箱管理员在哪里找?域名邮箱如何管理?
  18. c语言流水灯程序 16,16个发光二极管流水灯程序
  19. Java简易图书DVD管理系统
  20. 使用代理后,雷鸟连接qq邮箱

热门文章

  1. 备忘: MIRACL 大数运算库使用手册
  2. [短评] 关于顺丰快递大战阿里菜鸟物流事件的一点吐槽
  3. JavaWeb知识总结
  4. 从SDE库文件手工删除SDE图层(转载)
  5. php路径详解,详解与PHP路径相关的dirname,realpath,__FILE__函数
  6. 算数编码java_算术编码核心类
  7. fastjson版本_Fastjson高危漏洞风险提示
  8. c语言字符全排列数组,使用c语言递归实现字符串的全排列
  9. oracle hint firstrow,Dynamics AX 2009客户端配置文件启动路径问题
  10. mysql并发参数查看_MySQL Innodb 并发涉及参数