Logu P2118 ratio simplified, logu p2118 simplified
Description
On social media, we often see public opinion surveys and results on whether a certain opinion is accepted or not. For example, if there are 1498 people who have expressed support for a certain point of view and 902 people who have opposed it, the ratio of consent to opposition can be simply recorded as 1498: 902.
However, if we present the results in this way, most people will not be satisfied. Because the value of this ratio is too large, it is difficult to see their relationship at a glance. For the above example, if the ratio is recorded as, although there is a certain error with the actual results, it can still reflect the survey results more accurately and intuitively.
Now we provide support for number A, number B, and an upper limit of number L. Please simplify a to a to B ', it is required that, when neither 'A' nor B 'is greater than L and the mass of a' and B' (the maximum approximate number of two integers is 1, a'/B 'is ≥a/B and the value of A'/B'-A/B is as small as possible.
(This topic is 4noip universal T2)
Input/Output Format
Input Format:
The input contains three integers, A, B, and L. Each integer is separated by A space, indicating the number of supported persons, the number of opposing persons, and the upper limit.
Output Format:
The output contains two integers, A' and B ', which are separated by A space to indicate the ratio after simplification.
Input and Output sample input sample #1: Copy
1498 902 10
Output example #1: Copy
5 3
Description
For 100% of data, 1 ≤ A ≤ 1,000,000, 1 ≤ B ≤ 1,000,000, 1 ≤ L ≤ 100, A/B ≤ L.
I thought it was a profound mathematical question.
However, after reading the data, we found that L is relatively small, so we can simply list the data in brute force mode.
#include<cstdio>#include<algorithm>const int MAXN=3*1e6+10;using namespace std;inline int read(){ char c=getchar();int x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f;}int main(){ int x=read(),y=read(),L=read(); int ansx=233333,ansy=1; for(int i=1;i<=L;i++) for(int j=1;j<=L;j++) if( (double)i/j>=(double)x/y && (double)i/j < (double) ansx/ansy ) ansx=i,ansy=j; printf("%d %d",ansx,ansy); return 0;}