比赛 |
防止浮躁的小练习v0.2 |
评测结果 |
AAAAAAAAAA |
题目名称 |
比例简化 |
最终得分 |
100 |
用户昵称 |
Mealy |
运行时间 |
0.023 s |
代码语言 |
C++ |
内存使用 |
1.84 MiB |
提交时间 |
2016-10-08 10:32:45 |
显示代码纯文本
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- const int nmax=100001;
- int n,m,lim;
- int cnt=0;
- double tmpr,tmpu;
- class Poi
- {
- public:
- int l;
- int r;
- double derta;
- }poi[nmax];
- bool cmp(Poi a,Poi b)
- {
- if(a.derta==b.derta)
- return a.l<b.l;
- return a.derta<b.derta;
- }
- void PreDo()
- {
- scanf("%d%d%d",&n,&m,&lim);
- tmpr=((double)1*n)/((double)1*m);
- for(int i=1;i<=lim;i++)
- for(int j=1;j<=lim;j++)
- {
- tmpu=((double)1*i)/((double)1*j);
- if(tmpu>=tmpr)
- {
- poi[++cnt].l=i;
- poi[cnt].r=j;
- poi[cnt].derta=tmpu-tmpr;
- }
- }
- sort(poi+1,poi+cnt+1,cmp);
- printf("%d %d",poi[1].l,poi[1].r);
- }
- int main()
- {
- freopen("ratio.in","r",stdin);
- freopen("ratio.out","w",stdout);
- PreDo();
- return 0;
- }