NOIP 普及组 2014 比例简化

传送门

https://www.cnblogs.com/violet-acmer/p/9898636.html

题解:

  一开始想多了,以为得保证两者之间的相对比率,至少不能改变的太离谱啊。

  but,直接暴力就过了。。。。。。。

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 #define eps 1e-8
 5 #define P pair<int ,int >
 6 const int maxn=100+10;
 7 int A,B,L;
 8 int prime[maxn][maxn];
 9 int tot[maxn];
10 bool isPrime(int x,int y)//判断 x 与 y 是否互质
11 {
12     if(x < y)
13         swap(x,y);
14     for(int i=2;i <= y;++i)
15         if(x%i == 0 && y%i == 0)
16             return false;
17     return true;
18 }
19 void Solve()
20 {
21     P res;
22     res=P(0,0);
23     for(int i=1;i <= L;++i)
24         for(int j=1;j <= L;++j)
25             if(isPrime(i,j) && i*B >= j*A)
26             {
27                 if(res.first == 0 || i*res.second < j*res.first)
28                     res.first=i,res.second=j;
29             }
30     printf("%d %d\n",res.first,res.second);
31 }
32 int main()
33 {
34     scanf("%d%d%d",&A,&B,&L);
35     Solve();
36 }
View Code

猜你喜欢

转载自www.cnblogs.com/violet-acmer/p/9898830.html