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 ...
随机推荐
- Vue Router 相关
1. 路由传参: 编程式的导航 router.push this.$router.push("home"); this.$router.push({ name: 'news', p ...
- Django项目:CRM(客户关系管理系统)--09--04PerfectCRM实现King_admin注册功能01
- Django项目:CRM(客户关系管理系统)--03--02PerfectCRM创建ADMIN页面01
八.CRM项目创建king_admin python.exe manage.py startapp king_admin 'king_admin', 九.CRM项目分发URL "" ...
- HR招聘_(十)_招聘方法论(供应商管理)
招聘和供应商长期合作,所以供应商管理也至关重要.供应商一般分为猎头,渠道,外包三类. 猎头 高端职位,高难度职位,急需职位和量大职位会和猎头公司合作共同完成招聘任务,猎头公司一般会有两种服务,猎头和R ...
- 找不到windows.h源文件
一.找不到源文件window.h 今天在网上下了个程序,在公司用VS2015能打开,在家用VS2017却打不开,提示找不到源文件window.h,因为引用了这个头文件,但是却找不到 解决方案: 右侧解 ...
- AOP Aspect 统一日志、异常处理、数据格式 【转】
package com.gsww.chis.aop; import java.util.Arrays; import com.google.common.base.Throwables; import ...
- MVC开发模式与web经典三层框架
MVC:Model(模型)-View(视图)-Controller(控制器) ----是一种软件架构模式,一般把软件系统拆分为这三个层次. 视图View层:前端交互界面或者后端系统界面,它从模型中获取 ...
- Direct2D 第5篇 绘制图像
原文:Direct2D 第5篇 绘制图像 我加载的图像是一张透明底PNG图像,背景使用渐变的绿色画刷 #include <windows.h> #include <d2d1.h> ...
- Mac上定时运行脚本工具--launchctl
在Mac上可以像在Linux上一样,使用crontab来定时运行脚本,但苹果并不推荐这个方法.苹果推荐使用Launchctl来完成定时任务. 首先,我们先写一个可执行的脚本,列子为php脚本,名字为t ...
- Oracle 定义变量总结
首先,当在cmd里办入scott密码提示错误时,可以这样改一下,scott的解锁命令是: 以system用户登录:cmdsqlplus system/tigertigeralter user scot ...