XTU 1236 Fraction
Fraction |
||
Accepted : 168 | Submit : 1061 | |
Time Limit : 1000 MS | Memory Limit : 65536 KB |
FractionProblem Description:Everyone has silly periods, especially for RenShengGe. It's a sunny day, no is much more convient than 0.33333... as an example to support his So, RenShengGe lists a lot of numbers in textbooks and starts his great work. But RenShengGe is famous for his persistence, so he decided to sacrifice some InputThe first line contains a number T(no more than 10000) which represents the And there followed T lines, each line contains a finite decimal fraction x . OutputFor each test case, transform x in RenShengGe's rule. Sample Input3 Sample Output1/1 tipYou can use double to save x; |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int gcd(int a,int b)
{
int c,t;
if(a<b)
{
t=a,a=b,b=t;
}
while(b)
{
c=a%b;
a=b;
b=c;
}
return a;
}
int main()
{
int i,j,T;
double s,minn;
scanf("%d",&T);
while(T--)
{
scanf("%lf",&s);
int a=,b=;
minn=s;
for(i=; i<=; i++) //枚举1-1000的分母
{
j=s*i+0.5; //求出分子
double f=j*1.0/i; //计算此时分数的结果
double p=fabs(f-s); //与原来的数进行比较
if(minn>p)
{
minn=p;
a=j;
b=i;
}
}
int r=gcd(a,b); //求最大公约数,化简
printf("%d/%d\n",a/r,b/r);
}
return ;
}
XTU 1236 Fraction的更多相关文章
- XTU1236 Fraction
Fraction Accepted : 124 Submit : 806 Time Limit : 1000 MS Memory Limit : 65536 KB Fraction Problem D ...
- [LeetCode] Fraction to Recurring Decimal 分数转循环小数
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- Slave I/O: Got fatal error 1236
[起因] 一次zabbix报警,从库[Warning] MySQL-repl was down # 不知道主库/storage空间小于20%时为什么没有触发trigger [从库错误日志] 1611 ...
- BZOJ 1236: SPOJ1433 KPSUM
Description 用+-号连接1-n所有数字的数位,问结果是多少. Sol 数位DP. \(f[i][j][0/1][0/1]\) 表示长度为 \(i\) 的数字,开头数字是 \(j\) ,是否 ...
- POJ 1236 Network of Schools(Tarjan缩点)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16806 Accepted: 66 ...
- poj 1236 Network of Schools(连通图)
题目链接:http://poj.org/problem?id=1236 题目大意:有一些学校,学校之间可以进行收发邮件,给出学校的相互关系,问:1.至少 要向这些学校发送多少份才能使所有的学校都能获得 ...
- 1236 - Pairs Forming LCM -- LightOj1236 (LCM)
http://lightoj.com/volume_showproblem.php?problem=1236 题目大意: 给你一个数n,让你求1到n之间的数(a,b && a<= ...
- 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 ...
随机推荐
- Leetcode606.Construct String from Binary Tree根据二叉树创建字符串
你需要采用前序遍历的方式,将一个二叉树转换成一个由括号和整数组成的字符串. 空节点则用一对空括号 "()" 表示.而且你需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空 ...
- CSS实现火焰效果
代码如下 //主要就是用css动画实现的 <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- ecshop二次开发之电子票
前台效果展示: 2. 3. 后台展示效果: 代码实现: 一. 添加菜单项:路径admin\includes\inc_menu.PHP $modules['18_ticket_m ...
- Linux操作系统各版本ISO镜像下载(包括oracle linux\redhat\centos\u
Linux操作系统各版本ISO镜像下载(包括oracle linux\redhat\centos\ubuntu\debian等) 1.Oracle Linux(下载地址) (1)OracleLinux ...
- SCAN listener and Node listener – How does it work
http://www.mydbspace.com/? p=324 Single Client Access Name (SCAN) is new feature of oracle 11gR2 gri ...
- pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')
pymysql错误: pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query') pymy ...
- 春蔚专访--MaxCompute 与 Calcite 的技术和故事
摘要:2019大数据技术公开课第一季<技术人生专访>,来自阿里云计算平台事业部高级开发工程师雷春蔚向大家讲述了MaxCompute 与 Calcite 的技术和故事. 具体内容包括: 1) ...
- 【转载】遗传算法及matlab实现
摘自https://www.cnblogs.com/LoganChen/p/7509702.html 1.遗传算法介绍 遗传算法,模拟达尔文进化论的自然选择和遗产学机理的生物进化构成的计算模型,一种不 ...
- Java中的TreeMap及红黑树
TreeMap: http://blog.csdn.net/tobeandnottobe/article/details/7232664 红黑树: http://blog.chinaunix.net/ ...
- 洛谷2501 BZOJ1801中国象棋题解
题目链接 BZ链接 其实dp只要把状态想好后转移就很好写了(flag*1) f[i][j][k]表示到了第i行,有j列放了一个跑,有k列放了两个跑的方案总数 然后大力讨论,转移即可 # include ...