2015湖南湘潭 D 二分
Fraction |
||
| Accepted : 133 | Submit : 892 | |
| 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 decimal fractions are too complicate, and set that is much more convient than 0.33333... as an example to support his theory. 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 the decimal fraction under his restriction. If several fractions satifies the restriction, he chooses the smallest one with simplest formation. 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; |
#include<bits/stdc++.h>
using namespace std;
#define eps 0.00000001
struct gg
{
double num;
int a,b;
} ans[];
int cmp(gg x,gg y)
{
return x.num<y.num;
}
int main()
{
int i,j,t;
t=;
ans[t].num=;
ans[t].a=;
ans[t++].b=;
for(i=; i<=; i++)
{
for(j=; j<i; j++)
{
if(__gcd(i,j)>) continue;
double x=j*1.0/i;
ans[t].num=x;
ans[t].a=j;
ans[t++].b=i;
}
}
ans[t].num=;
ans[t].a=;
ans[t++].b=;
sort(ans,ans+t,cmp);
int T;
double x;
scanf("%d",&T);
while(T--)
{
scanf("%lf",&x);
int l=,r=t,mid;
while(l<r)
{
mid=(l+r)/;
if(fabs(x-ans[mid].num)<eps) break;
if(x>ans[mid].num) l=mid+;
else r=mid;
}
int sign1=mid-,sign2=mid,sign3=mid+,sign;
double flag1=,flag2=,flag3=,flag;
if(sign1>=) flag1=ans[sign1].num;
if(sign2>=) flag2=ans[sign2].num;
if(sign3>=) flag3=ans[sign3].num;
if(fabs(flag1-x)<fabs(flag2-x)) sign=sign1;
else sign=sign2;
flag=ans[sign].num;
if(fabs(flag-x)>fabs(flag3-x)) sign=sign3;
printf("%d/%d\n",ans[sign].a,ans[sign].b);
}
return ;
}
2015湖南湘潭 D 二分的更多相关文章
- Google Code Jam Round 1A 2015 Problem B. Haircut 二分
Problem You are waiting in a long line to get a haircut at a trendy barber shop. The shop has B barb ...
- codeforces Looksery Cup 2015 H Degenerate Matrix 二分 注意浮点数陷阱
#include <cstdio> #include <cstring> #include <algorithm> #include <string> ...
- noip2012~2015刷题小记录
2012d1t1 密码 模拟题 #include<cstdio> #include<cstdlib> #include<cstring> #include<c ...
- 天气预报API(二):全球城市、景点代码列表(“旧编码”)
说明 2016-12-10 补充 (后来)偶然发现中国天气网已经有城市ID列表的网页...还发现城市编码有两种,暂且称中国天气网这些编码为旧标准"旧编码"的特征是 9个字符长度; ...
- 人物-IT-刘强东:刘强东
ylbtech-人物-IT-刘强东:刘强东 刘强东,男,汉族,1973年3月10日生(另一说法:1974年2月14日),江苏宿迁人,祖籍湖南湘潭 .京东集团董事局主席兼首席执行官,本科毕业于中国人民大 ...
- 基于SCADA数据驱动的风电机组部件故障预警
吴亚联 1 , 梁坤鑫 1 , 苏永新 1* , 詹 俊 2(1.湘潭大学 信息工程学院, 湖南 湘潭 411105: 2.湖南优利泰克自动化系统有限公司, 湖南 长沙 410205) 摘 要: 为提 ...
- Android之控件使用
Android系统为我们提供了大量的控件,例如:开关控件.单选按钮.多选按钮.单选菜单等等,那么这些控件如何使用呢?本篇我将带领大家一道学习一下如何使用这些控件.所谓无图无真相,先让大家看一下效果图: ...
- 时隔3年,再次折腾BlackBerry 8830!
2010年手头换得8830,之后就是好几番刷机.解SPC.倒腾各种软件..算软件注册码..那个时候记得最难弄的注册码就是crunchSMS.需要运行虚拟机来从内存地址读取注册码..不过黑莓真的很经得起 ...
- Power Map
推荐64位版本Office,但会遇到以下问题 建议大多数用户使用 32 位 Office 我们建议使用 32 版本的 Office,因为它与大多数其他应用程序更加兼容,尤其是第三方加载项.这也是默认安 ...
随机推荐
- vconsole h5应用ajax请求抓包
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta co ...
- YUM软件包额外扩展了解项
5.YUM配置文件 yum的配置一般有两种方式: 一种是直接配置/etc目录下的yum.conf文件, 另外一种是在/etc/yum.repos.d目录下增加.repo文件 [root@xuliang ...
- django 不同版本 url 及path区别
- Zabbix结合Grafana绘图
参考网站: https://www.jianshu.com/p/6eec985c5c94 注意事项: 1.在ganafa添加datasource的时候url写成http://10.116.33.116 ...
- spring boot 整合案例
github : https://github.com/nbfujx/springBoot-learn-demo
- Redis 集合 set 操作, 有序集合
01, 唯一性, 确定性, 无序性 ( 结合的三大特性 ) 02, 新建集合, 或者往集合中添加数据 => sadd key value1 value2 value3 ....... 03, 查 ...
- web 复制功能和span光标
参考文章:https://www.cnblogs.com/tugenhua0707/p/7395966.html https://blog.csdn.net/woshinia/article/deta ...
- 关于gevent的一些理解(一)
前言:gevent是python的一个并发框架,以微线程greenlet为核心,使用了epoll事件监听机制以及诸多其他优化而变得高效.而且其中有个monkey类, 将现有基于Python线程直接转化 ...
- mongodb基础学习14-mapReduce操作
mapReduce随着大数据的兴起而流行,相当于传统数据库的group操作,强项在于分布式计算. map:将一组记录的相关信息映射到一个数组 reduce:对map得到的数组数据进行处理得到一个结果 ...
- Access denied for user 'root'@'localhost' (using password:YES)解决方法
Access denied for user 'root'@'localhost' (using password:YES)解决方法 在MySQL的使用过程中,我们可能会碰到“Access denie ...