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,因为它与大多数其他应用程序更加兼容,尤其是第三方加载项.这也是默认安 ...
随机推荐
- js判断当前为pc端还是wap端
var checkBrowser; function browserRedirect() { var sUserAgent = navigator.userAgent.toLowerCase(); v ...
- Java面向对象技术
问题及答案来源自<Java程序员面试笔试宝典>第四章 Java基础知识 4.2面向对象技术 1.面向对象与面向过程有什么区别? 看下面一个实例即可: 面向过程就是分析出解决问题所需要的步骤 ...
- selenium+python自动化98--文件下载弹窗处理(PyKeyboard)
前言 在web自动化下载操作时,有时候会弹出下载框,这种下载框不属于web的页面,是没办法去定位的(有些同学一说到点击,脑袋里面就是定位!定位!定位!) 有时候我们并不是非要去定位到这个按钮再去点击, ...
- Nginx-ingress-controller部署
参考官网https://kubernetes.github.io/ingress-nginx/ 部署pod:nginx-ingress-controller/nginx-default-backend ...
- jqgird
将jqgird某字段设为超链接,并传递相关参数 cellvalue:为后台传递过来的字段数据 rowObject:为本行数据 实现: formatter:function(cellvalue, opt ...
- JAVA Spring 面向切面编程 基本案例(AOP)
< 1 > 配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&q ...
- DEMO: springboot 与 mybatis 集成
之前一直在用springMVC,接触到springboot之后,感觉使用起来方便多了,没那多xml需要配置. 先来看看整个项目结构,当然是maven项目. 1.测试数据 DROP TABLE IF E ...
- WMI 连接远程计算机并进行局域网进程扫描
On Error Resume Next Dim myArray(231) myArray(0)="smss.exe"myArray(1)="csrss.exe" ...
- Others-Goldengate 数据同步
GoldenGate 是一家创建于1995年的美国公司,开发总部设在旧金山,在北美,欧洲和亚洲(包括新加坡.印度.澳大利亚)设有支持中心. 公司名称 GoldenGate 总部地点 旧金山 成立时间 ...
- jenkins 没有maven选项,怎么办
第一步: 进入jenkins,点系统管理 第二:插件管理 点击“可选插件” 然后在右边的过滤输入框中输入搜索关键字: Maven Integration 或者 Pipeline Maven Int ...