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 ...
随机推荐
- 阿里云DMS发布数据库网关服务: 打通网络限制 开启数据库统一管理的万能钥匙
概述 阿里云数据管理DMS在云端可提供专业的数据库服务,除对标本地数据库软件的基础功能外,还包含性能诊断.数据追踪.跨实例SQL查询(含异构数据库类型之间)等专业性功能,同时提供审计安全和企业级数据库 ...
- H5C3--sessionStorage和localStorage的使用
一.sessionStorage的使用 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
- void 运算符
void 是 javascript 的操作符,意思是:只执行表达式,但没有返回值.该表达式会被计算但是不会在当前文档处装入任何内容,void其实是javascript中的一个函数,接受一个参数,返回值 ...
- python中的True和False
返回真假时,需要为: return True return False
- JavaScript字符串、数组、对象方法总结
字符串方法 示例字符串: const str = "hello,kitty,hello,vue "; 一.基本方法 charAt(n) 返回指定索引的字符 charCodeAt(n ...
- 写GULP遇到的ES6问题详解
Gulp.js 是一个自动化构建工具,开发者可以使用它在项目开发过程中自动执行常见任务.最近复习一下gulp一些基本的写法,在写了一些简单的uglify,rename,concat,clean的处理之 ...
- 【水滴石穿】MyFirstRNDemo
比较简单的项目 //index.js /** @format */ import {AppRegistry} from 'react-native'; //默认创建的类 import App from ...
- (转载)怎样解决SQL Server内存不断增加问题
在启用sqlserver服务后,发现进程sqlservr.exe的内存使用量从开始的100多MB持续增加,很快就高达1G以上,造成机器运行缓慢.卡机,严重影响使用.sql server 在查询大数据量 ...
- CentOS8.0-1905安装配置ftp服务器
关键词:CentOS8/RHEL8;安装配置FTP/安装配置VSFTPD;被动模式/PASV##CentOS8.0-1905发布后,尝试将FTP服务器迁移至新版本的CentOS中,但是测试过程中,在防 ...
- 使用 Windows 10 WSL 搭建 ESP8266 编译环境并使用 VSCODE 编程(一)(2019-08-23)
目录 使用 Windows 10 WSL 搭建 ESP8266 编译环境并使用 VSCODE 编程 安装前准备 安装 ESP8266 工具链 下载 ESP8266 SDK 编译 花絮 使用 Windo ...