XTU1236 Fraction
Fraction |
||
Accepted : 124 | Submit : 806 | |
Time Limit : 1000 MS | Memory Limit : 65536 KB |
FractionProblem Description:Everyone has silly periods, especially for RenShengGe. It's a sunny day, no one knows what happened to RenShengGe, RenShengGe says that he wants to change all decimal fractions between 0 and 1 to fraction. In addtion, he says So, RenShengGe lists a lot of numbers in textbooks and starts his great work. To his dissapoint, he soon realizes that the denominator of the fraction may be very big which kills the simplicity that support of his theory. But RenShengGe is famous for his persistence, so he decided to sacrifice some accuracy of fractions. Ok, In his new solution, he confines the denominator in [1,1000] and figure out the least absolute different fractions with InputThe first line contains a number T(no more than 10000) which represents the number of test cases. And there followed T lines, each line contains a finite decimal fraction x that satisfies . OutputFor each test case, transform x in RenShengGe's rule. Sample Input3 Sample Output1/1 tipYou can use double to save x; SourceXTU OnlineJudge |
- <span style="font-size:18px;">#include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <stack>
- #include <queue>
- #include <map>
- #include <set>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- const double eps = 1e-6;
- const double pi = acos(-1.0);
- const int INF = 0x3f3f3f3f;
- const int MOD = 1000000007;
- #define ll long long
- #define CL(a,b) memset(a,b,sizeof(a))
- #define lson (i<<1)
- #define rson ((i<<1)|1)
- #define MAXN 100010
- int main()
- {
- int T;
- double s,minx;
- scanf("%d",&T);
- while(T--)
- {
- scanf("%lf",&s);
- minx = s;
- int a=0,b=1;
- for(int i=1; i<=1000; i++)
- {
- int j = i*s+0.5;
- double f = j*1.0/i;
- double p = fabs(f-s);
- if(minx > p)
- {
- minx = p;
- a = j;
- b = i;
- }
- }
- int r = __gcd(a, b);
- printf("%d/%d\n",a/r,b/r);
- }
- return 0;
- }
- </span>
XTU1236 Fraction的更多相关文章
- [LeetCode] Fraction to Recurring Decimal 分数转循环小数
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- 【leetcode】Fraction to Recurring Decimal
Fraction to Recurring Decimal Given two integers representing the numerator and denominator of a fra ...
- Decimal To Fraction 小数转换成分数
以0.25为例, 0.25 * 100 = 25, 求25 和 100 的最大公约数gcd. 25/gcd 为分子. 100/gcd为分母. //小数转分数 //0.3 -> 3/10, 0.2 ...
- ✡ leetcode 166. Fraction to Recurring Decimal 分数转换 --------- java
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- Leetcode 166. Fraction to Recurring Decimal 弗洛伊德判环
分数转小数,要求输出循环小数 如2 3 输出0.(6) 弗洛伊德判环的原理是在一个圈里,如果一个人的速度是另一个人的两倍,那个人就能追上另一个人.代码中one就是速度1的人,而two就是速度为2的人. ...
- [LeetCode] Fraction to Recurring Decimal 哈希表
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- Java for LeetCode 166 Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- LeetCode Fraction to Recurring Decimal
原题链接在这里:https://leetcode.com/problems/fraction-to-recurring-decimal/ 题目: Given two integers represen ...
随机推荐
- String 字符串详解 / 常用API
String 详解 / 常用API 简介 String 是不可改变的字符串序列.String 为字符串常量 StringBuilder 与StringBuffer 均为可改变的字符串序列.为字符串变量 ...
- UVALive 6885 Flowery Trails 最短路
Flowery Trails 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid= ...
- 使用socket.io+redis来实现基本的聊天室应用场景
本文根据socket.io与Redis来实现基本的聊天室应用场景,主要表现于多个浏览器之间的信息同步和实时更新. 只是简单记录了一下, 更详细的内容可以参考后续的一篇补充文章: 使用node.js + ...
- MYSQL-5.5.37-win32.msi 这个版本得程序包谁有吗 可以给我一下吗?
之前下载了这个版本得mysql 但是跟服务器链接不上 后来我就卸载了 但由于卸载不干净 现在又删了注册表 好像把这个程序包得什么文件删除了 现在提示配置文件错误 所以有这个程序包得 ...
- 使用Device IO Control 讀寫 USB Mass Storage
http://www.ezblog.idv.tw/Download/USBStorage.rar 這是一個不透過檔案系統,去讀寫USB Mass Storage 任何位置(包含FAT)的方式 首先需安 ...
- 【Go入门教程7】面向对象(method、指针作为receiver、method继承、method重写)
前面两章我们介绍了函数和struct,那你是否想过函数当作struct的字段一样来处理呢?今天我们就讲解一下函数的另一种形态,带有接收者(receiver)的函数,我们称为method method ...
- 关于错误errno EFAULT:Bad address
UDP socket : read error Bad address 在写UDP server.在调用套接字读取的时候发生了这个错误. 通过看errno.h 能够看到相应的错误号 EFAULT: ...
- Unity3d Http Get请求
新浪微博的OpenAPI登录 public static IEnumerator LoginRequest(string userid, string passwd, Action<string ...
- iOS appStore中的应用 实现升级功能
.h文件中 <UIAlertViewDelegate> .m文件中 #import "SBJson.h" //解析sbjson 数据 - (void)vi ...
- 【转】利用HTML5开发Android
● Android设备多分辨率的问题 Android浏览器默认预览模式浏览 会缩小页面 WebView中则会以原始大小显示 Android浏览器和WebView默认为mdpi.hdpi相当于mdpi的 ...