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,因为它与大多数其他应用程序更加兼容,尤其是第三方加载项.这也是默认安 ...
随机推荐
- 洛谷P1414 又是毕业季II
题目背景 “叮铃铃铃”,随着高考最后一科结考铃声的敲响,三年青春时光顿时凝固于此刻.毕业的欣喜怎敌那离别的不舍,憧憬着未来仍毋忘逝去的歌.1000多个日夜的欢笑和泪水,全凝聚在毕业晚会上,相信,这一定 ...
- 解决Sybase PowerDesigner 数据库设计中 Name 自动填充Code
在使用 Sybase PowerDesigner 进行数据库设计时,为了理清思路,需要将name改为中文名称,但是这个软件会自动将name填 充为code,可以通过如下配置修改: 选择tools-&g ...
- 显示锁(一)Lock显示锁的优点
转载自 Java 并发:Lock 框架详解 摘要: 我们已经知道,synchronized 是java的关键字,是Java的内置特性,在JVM层面实现了对临界资源的同步互斥访问,但 synchroni ...
- python pip使用报错:Fatal error in launcher: Unable to create process using '"'
在一个系统中共存Python2.python3的时候,pip.pip2.pip3使用的时候会报错: c:\Python35\Scripts>pip3Fatal error in launcher ...
- PHP获取照片exif信息
在这个没图说个屁的年代,照片还是很重要的.如果照片上传后会自动加上 照片相关信息,那用户体验的确会好很多,本着这个想法,今天尝试了下 PHP获取照片exif信息,重要的是 获取图片的GPS信息,如果再 ...
- windows10系统右键添加cmd命令
https://blog.csdn.net/Mr_BEelzebub/article/details/78776104 首先,在桌面新建一个文本文档. Windows Registry Editor ...
- js 层随着滚动条上下移动
var tips; var theTop = 10; /*这是默认高度,越大越往下*/ var old = theTop; function moveTips() { var tt = 0; if ( ...
- 转载:canal数据库同步redis
ref: http://blog.csdn.net/tb3039450/article/details/53928351
- java web 跨域
服务器端解决跨域问题的三种方法 跨域是指html文件所在的服务器与ajax请求的服务器是不同的ip+port,例如: - ‘192.168.1.1:8080’ 与 ‘192.168.1.2:808 ...
- TortoiseGit 使用 HTTP 方式每次 PUSH 无需输入密码的方法
由于 BitBucket 被墙,导致使用时只能用HTTPS代理的方式,但TortoiseGit貌似没有记忆密码的功能,以至于每次push时都要求输入密码,很是麻烦!在网上搜到的保存密码的方式也有点笨. ...