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,因为它与大多数其他应用程序更加兼容,尤其是第三方加载项.这也是默认安 ...
随机推荐
- 建造者模式(Builder)
Separate the construction of a complex object form its representation so that the same construction ...
- java内存模型(二)深入理解java内存模型的系列好文
深入理解java内存模型(一)--基础 深入理解java内存模型(二)--重排序 深入理解java内存模型(三)--顺序一致性 深入理解java内存模型(四)--volatile 深入理解java内存 ...
- Rust笔记
前言: 学了有段时间了,现在同步到博客园. 正文: Rust语言介绍 l Rust由js之父开发的新型语言,打破了传统的难以接触底层的局面.这是个有C++开发的语言.拥有C的血统 l Rust必须严格 ...
- css的样式
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- java的锁机制,synchronize与Lock比较
参考:https://blog.csdn.net/dahongwudi/article/details/78201082
- Spring 配置 web.xml (防止spring 内存溢出)
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" " ...
- [ilink32 Error] Error: Unresolved external '__fastcall Data::Win::Adodb::TCustomADODataSet
[ilink32 Error] Error: Unresolved external '__fastcall Data::Win::Adodb::TCustomADODataSet::GetParam ...
- 取得grid单元格里刚输入的文本,未保存的文本
取得grid单元格里刚输入的文本内容,未保存的文本,正在输入的值,正在编辑的值,编辑框 dbgrid->DataSource->DataSet->UpdateRecord(); pr ...
- 调用css文件,进行调色
Title 小米 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- app.$mount("#app") 手动挂载
$mount()手动挂载 当Vue实例没有el属性时,则该实例尚没有挂载到某个dom中: 假如需要延迟挂载,可以在之后手动调用vm.$mount()方法来挂载.例如: new Vue({ //el: ...