POJ 1650 Integer Approximation
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5081 | Accepted: 1652 |
Description
Input
Output
Sample Input
- 3.14159265358979
- 10000
Sample Output
- 355 113
题目大意:给出一个数字x和一个范围,在这个方位内招两个数字,是它们的商最接近x。
解题方法:直接枚举,取a,b为1每次对a,b求商,如果a / b > x,则a增加1,否则b增加1,每次记录下差值最小时a,b的值。
- #include <stdio.h>
- int main()
- {
- double x, a, b, n, Min, n1, n2;
- scanf("%lf%lf", &x, &n);
- a = ;
- b = ;
- Min = n + ;
- while(a <= n && b <= n)
- {
- if (a / b > x)
- {
- if (a / b - x < Min)
- {
- Min = a / b - x;
- n1 = a;
- n2 = b;
- }
- b++;
- }
- else
- {
- if (x - a / b < Min)
- {
- Min = x - a / b;
- n1 = a;
- n2 = b;
- }
- a++;
- }
- }
- printf("%.0f %.0f\n", n1, n2);
- return ;
- }
POJ 1650 Integer Approximation的更多相关文章
- Poj 1503 Integer Inquiry
1.链接地址: http://poj.org/problem?id=1503 2.题目: Integer Inquiry Time Limit: 1000MS Memory Limit: 1000 ...
- poj 1716 Integer Intervals (差分约束 或 贪心)
Integer Intervals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12192 Accepted: 514 ...
- POJ 1503 Integer Inquiry 大数 难度:0
题目链接:http://poj.org/problem?id=1503 import java.io.*; import java.math.BigInteger; import java.util. ...
- POJ 1716 Integer Intervals 差分约束
题目:http://poj.org/problem?id=1716 #include <stdio.h> #include <string.h> #include <ve ...
- poj 1503 Integer Inquiry (高精度运算)
题目链接:http://poj.org/problem?id=1503 思路分析: 基本的高精度问题,使用字符数组存储然后处理即可. 代码如下: #include <iostream> # ...
- POJ 1503 Integer Inquiry(大数相加)
一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...
- POJ 1201 Intervals || POJ 1716 Integer Intervals 差分约束
POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai, ...
- poj 1716 Integer Intervals(差分约束)
1716 -- Integer Intervals 跟之前个人赛的一道二分加差分约束差不多,也是求满足条件的最小值. 题意是,给出若干区间,需要找出最少的元素个数,使得每个区间至少包含两个这里的元素. ...
- POJ 1503 Integer Inquiry(大数相加,java)
题目 我要开始练习一些java的简单编程了^v^ import java.io.*; import java.util.*; import java.math.*; public class Main ...
随机推荐
- CSS扇形展开效果
知识点预备: [1]CSS3中特别重要的transform中的rotate(),现在transform可以将元素进行2D和3D变形. 2D transform常用的transform-function ...
- Redis安装与日常使用
下载与安装 $ wget http://download.redis.io/releases/redis-3.0.3.tar.gz $ tar xzf redis-3.0.3.tar.gz $ cd ...
- atitit.提升备份文件复制速度(3) ----建立同步删除脚本
atitit.提升备份文件复制速度(3) ----建立同步删除脚本 1. 建立同步删除脚本两个方法.. 1 2. 1从回收站info2文件... 1 3. 清理结束在后snap比较 1 4. Npp ...
- 更新日志 - fir.im 回归,上线 Android Studio 插件
上周 fir.im 经历了一场前所未有的挑战,因为自查应用网站暂停,在事情发生4天内我们完成了自查,fir.im 正式回归.煎熬的 98 个小时,感谢开发者与用户对我们的信任和支持. 使用注意: 禁止 ...
- Singleton模式和Mono-State模式
类和实例 对于大多数的类,都可以创建多个实例.在需要和不需要时,创建和删除这些实例.该过程会伴随着内存的分配和归还. 同时,有一些类,应该仅有一个实例.该实例在程序启动/结束时被创建和删除. root ...
- Django基础——Model篇(二)
一 Model连表关系 一对多:models.ForeignKey(其他表) 多对多:models.ManyToManyField(其他表) 一对一:models.OneToOneFiel ...
- Leetcode 278 First Bad Version 二分查找(二分下标)
题意:找到第一个出问题的版本 二分查找,注意 mid = l + (r - l + 1) / 2;因为整数会溢出 // Forward declaration of isBadVersion API. ...
- 安装 Autoconf 2.69版
发生错误configure.ac:8: error: Autoconf version 2.64 or higher is required 1.检查版本 [root@localhost Deskto ...
- HTML常用命名和CSS reset代码【收集总结】
CSS命名规则 头:header 内容:content/containe 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体布局宽度:wrapper 左右中:l ...
- QueryTask查询结果最多500条的问题
参考: http://dingtao-wgs.blog.163.com/blog/static/5026071420129813059865/ 上面文章中给出的解决方法:今天在做querytask的时 ...