Codeforces #172 div2的B题
来源:互联网 发布:可变数据喷码机 编辑:程序博客网 时间:2024/05/22 00:09
题目意思还是很清楚的,要找一个分数使得它与x/y的差最小,要求分母b<n,b要最小,分子也最小的那个。
昨晚纠结了半天,还是没纠结出来,今天把它a了。。。。。。
#include<iostream>#include<cstdio>#include<cstring>using namespace std;double go(double xy,int a,int b){ double s=((double)a)/((double)b)-xy; if(s>0)return s; else return -s;}int main(){ int x,y,n; while(scanf("%d%d%d",&x,&y,&n)!=EOF) { double xy=((double)x)/((double)y); int a,b,j=0; double ss=110005,v; for(int i=1;i<=n;i++) { while(go(xy,j,i)>go(xy,j+1,i))j++; v=go(xy,j,i); if(v<ss) { ss=v; a=j; b=i; } if(ss==0)break; } cout<<a<<"/"<<b<<endl; } return 0;}
- Codeforces #172 div2的B题
- codeforces 260 div2 B题
- codeforces 105 div2 B
- codeforces 148 div2 B
- Codeforces #103 div2 B
- codeforces 257 div2 B
- Codeforces #263 Div2 B
- codeforces #Round354-div2-B
- codeforces #383 (div2) B
- codeforces #120 div2 B. Surrounded
- Codeforces #165 div2 B Multithreading
- codeforces div2 round#231 B
- codeforces div2 round#230 B
- Codeforces 201(DIV2)B
- codeforces#336 div2 A,B
- Codeforces Round #421(Div2) B
- Codeforces Round #429 (Div2) B
- codeforces#259 div2 (a,b,c)三题
- PHP中 ADODB 类库介绍
- 加密
- vim多标签和多窗口
- android进度条的样式
- Ice 的 Nonmutating 和 Idempotent
- Codeforces #172 div2的B题
- 接收微信的请求信息
- 判断上传文件是否是图片格式
- Python安装模块出错(ImportError: No module named setuptools)解决方法
- Linux内核中CPU主频和电压调整 (二)
- 计算机视觉与模式识别研究组--上海交大
- FCKeditor上传路径从绝对路径改成相对路径的方法 .
- give you the answer that why using "PRESERVE8" in startup code
- 电阻技术触摸屏的校正算法及应用编程设计(转)