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 ...
随机推荐
- JSPatch中的OC高级语法
1)多线程相关 dispatch_after dispatch_async dispatch_sync dispatch_get_main_queue dispatch_get_global_queu ...
- [BTS] Exception occurred when persisting state to the database
Error 1 Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'J ...
- jQuery Ztree基本用法
1.首先在页面上有<ul/>标签 <ul id="tree" class="ztree"></ul> 2.定义ztree的配 ...
- 浅谈压缩感知(二十八):压缩感知重构算法之广义正交匹配追踪(gOMP)
主要内容: gOMP的算法流程 gOMP的MATLAB实现 一维信号的实验与结果 稀疏度K与重构成功概率关系的实验与结果 一.gOMP的算法流程 广义正交匹配追踪(Generalized OMP, g ...
- mysql join 查询图
mysql join 查询,特别是对查两个表之间的差集,可以用table字段=null来做. 注意千万不是join on XX!=XX ,这样出来的结果是错误的.
- atitit.二维码生成总结java zxing
atitit.二维码生成总结java zxing #-----zxing类库.. but zxing3.0 的类库core-3.0.jar 需要jdk7 只好zing2.2.jar ..jdk6走o ...
- Cocoa编程开发者手册
Cocoa编程开发者手册(Objective-C权威著作超一流翻译阵容) [美] 奇斯纳尔(Chisnall,D.) 著 霍炬等 译 ISBN 978-7-121-12239-2 2013年7月出版 ...
- JavaScript 语句 while
while 语句用法 与for语句的用法之间的关系 for(i==1;i<5;i++) {document.write("12378<br />") } 若使用 ...
- DataGridView很详细的用法(转载)
一.DataGridView 取得或者修改当前单元格的内容: 当前单元格指的是 DataGridView 焦点所在的单元格,它可以通过 DataGridView 对象的 CurrentCell 属性取 ...
- BizTalk 2013R2 WCF-LOB Oracle Adapter安装配置/问题&解决方法
BizTalk 2013R2 WCF-LOB Oracle Adapter安装配置/问题&解决方法 安装Oracle Adapter 安装Oracle客户端 BizTalk 2013R2 安装 ...