枚举分母,然后离他最近的分子只有两个,分别判断一下能不能用来更新答案即可

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int a,b,aa,ab;
double mx=10;
void wk(int x,int y)
{
if(x*b==y*a)
return;
if(fabs((double)x/y-(double)a/b)<mx)
{
mx=fabs((double)x/y-(double)a/b);
aa=x,ab=y;
}
}
int main()
{
scanf("%d%d",&a,&b);
for(int i=1;i<=32767;i++)
wk(floor((double)a/b*i),i),wk(floor((double)a/b*i)+1,i);
printf("%d %d\n",aa,ab);
return 0;
}

bzoj 1684: [Usaco2005 Oct]Close Encounter【数学(?)】的更多相关文章

  1. BZOJ 1684: [Usaco2005 Oct]Close Encounter

    题目 1684: [Usaco2005 Oct]Close Encounter Time Limit: 5 Sec  Memory Limit: 64 MB Description Lacking e ...

  2. 1684: [Usaco2005 Oct]Close Encounter

    1684: [Usaco2005 Oct]Close Encounter Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 387  Solved: 181[ ...

  3. 【BZOJ】1684: [Usaco2005 Oct]Close Encounter(暴力+c++)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1684 这货完全在考精度啊.. 比如奇葩 (llf)a/b*i (llf)(a/b*i)和(llf)( ...

  4. bzoj1684 [Usaco2005 Oct]Close Encounter

    Description Lacking even a fifth grade education, the cows are having trouble with a fraction proble ...

  5. bzoj:1685 [Usaco2005 Oct]Allowance 津贴

    Description As a reward for record milk production, Farmer John has decided to start paying Bessie t ...

  6. BZOJ 1685 [Usaco2005 Oct]Allowance 津贴:贪心【给硬币问题】

    题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1333 题意: 有n种不同币值的硬币,并保证大币值一定是小币值的倍数. 每种硬币的币值为 ...

  7. bzoj1745[Usaco2005 oct]Flying Right 飞行航班*

    bzoj1745[Usaco2005 oct]Flying Right 飞行航班 题意: n个农场,有k群牛要从一个农场到另一个农场(每群由一只或几只奶牛组成)飞机白天从农场1到农场n,晚上从农场n到 ...

  8. 【BZOJ】1685: [Usaco2005 Oct]Allowance 津贴(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1685 由于每个小的都能整除大的,那么我们在取完大的以后(不超过c)后,再取一个最小的数来补充,可以证 ...

  9. BZOJ 1742: [Usaco2005 nov]Grazing on the Run 边跑边吃草( dp )

    dp... dp( l , r , k )  , 表示 吃了[ l , r ] 的草 , k = 1 表示最后在 r 处 , k = 0 表示最后在 l 处 . ------------------- ...

随机推荐

  1. Springboot 缓存使用

    . CachingProvider . CacheManager . Cache . Entry . Expiry 1. 开启基于注解的缓存 @EnableCaching 下面列出几个核心的注解 @C ...

  2. JavaEE JDBC 事务

    JDBC 事务 @author ixenos 事务 1.概念:我们将一组语句构建成一个事务(trans action),当所有语句顺利执行之后,事务可以被提交(commit):否则,如果其中某个语句遇 ...

  3. 选择器的使用(target选择器)

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta ...

  4. 打造Spring Cloud构建微服务架构的最全资料

    访问: https://git.oschina.net/didispace/SpringCloud-Learning http://blog.didispace.com/categories/Spri ...

  5. intellij使用tomcat搭建servlet运行时环境

    http://suiyu.online/2017/08/01/intellij%E4%BD%BF%E7%94%A8tomcat%E6%90%AD%E5%BB%BAservlet%E8%BF%90%E8 ...

  6. laravel email markdown

    laravel 邮件使用markdown php artisan make:mail lessonPublished --markdown="emails.published" 这 ...

  7. SaltStack学习系列之state常用模块

    常用模块:cron,cmd,file,mount,ntp,pkg,service,user,group cmd模块 参数: name:要执行的命令 unless:用于检查的命令,只有unless指向的 ...

  8. win7开启超级管理员账户(Administrator)

    win7开启超级管理员账户(Administrator) 不同于XP系统,Windows7系统据说出于安全的考虑,将超级管理员帐户"Administrator"在登陆界面给隐藏了, ...

  9. 【Android】应用安全——反编译

    用java开发最操心的就是得到反编译,所以作为开发人员我们须要知道怎么反编译,那样才干知道怎样防止反编译.保证代码安全. 以下来看下比較经常使用的方法! 第一种方式:利用apktool反编译 1,首先 ...

  10. 字符串处理(正则表达式、NSScanner扫描、CoreParse解析器)-b

    搜索 在一个字符串中搜索子字符串 最灵活的方法 1 - (NSRange)rangeOfString:(NSString *)aString options:(NSStringCompareOptio ...