poj 1650 Integer Approximation
来源:互联网 发布:vps数据库地址 编辑:程序博客网 时间:2024/05/26 19:17
Integer Approximation
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4550 Accepted: 1445
Description
The FORTH programming language does not support floating-point arithmetic at all. Its author, Chuck Moore, maintains that floating-point calculations are too slow and most of the time can be emulated by integers with proper scaling. For example, to calculate the area of the circle with the radius R he suggests to use formula like R * R * 355 / 113, which is in fact surprisingly accurate. The value of 355 / 113 ≈ 3.141593 is approximating the value of PI with the absolute error of only about 2*10-7. You are to find the best integer approximation of a given floating-point number A within a given integer limit L. That is, to find such two integers N and D (1 <= N, D <= L) that the value of absolute error |A - N / D| is minimal.
Input
The first line of input contains a floating-point number A (0.1 <= A < 10) with the precision of up to 15 decimal digits. The second line contains the integer limit L. (1 <= L <= 100000).
Output
Output file must contain two integers, N and D, separated by space.
Sample Input
3.14159265358979 10000
Sample Output
355 113
Source
Northeastern Europe 2001, Far-Eastern Subregion
很简单,直接贴代码:
#include<stdio.h>#include<math.h>int main(){int N, D, L;double A, min=9999, temp;scanf("%lf %d",&A, &L);int i=1,j=1;while(i<=L && j<=L){ temp=fabs(j*1.0/i-A); if(temp<min ) { D=i; N=j; min=temp; } if(j*1.0/i>=A) i++; else if(j*1.0/i<=A) j++; }printf("%d %d\n",N,D);}
- poj 1650 Integer Approximation
- POJ 1650 Integer Approximation 笔记
- poj 1650 Integer Approximation “追赶法”搜索
- POJ 1650 Integer Approximation (追赶法求解)
- Poj 1650 & Zoj 1601 Integer Approximation (追赶法,分数逼近实数)
- ZOJ1601:Integer Approximation
- 追赶法-ZOJ-1601-Integer Approximation
- POJ1650 Integer Approximation(“追赶法”搜索)
- Approximation Algorithms
- POJ 1716 Integer Intervals
- poj 1716 Integer Intervals
- POJ 1503 Integer Inquiry
- poj 1503 Integer Inquiry
- POJ 1503 Integer Inquiry
- poj 1503 Integer Inquiry
- POJ 1503 Integer Inquiry
- POJ 1503 Integer Inquiry
- POJ 1716 Integer Intervals
- asp.net中,js改变textBox的文本内容的触发事件是onpropertychange
- linux c 创建守护进程
- OpenCV2 +Visual Studio 安装步骤
- 自定义listview
- 初识Silverlight
- poj 1650 Integer Approximation
- View编程(1): Window、View与setContentView()
- gwt集成Hiberater不能用Google App Engine启动
- [教学] [PCEVA超频宝典之CPU进阶篇]AM3平台超频教程
- vc下 获取工程exe文件的相对路径
- 解决"No CurrentSessionContext configured…
- javamail发信带附件的问题
- 关于Tomcat 不能识别 Eclipse工作区间 Java web 工程
- javascript的函数function