2 条题解

  • 2
    @ 2023-7-31 18:41:57
    #include<bits/stdc++.h>
    using namespace std;
    int a,b,l,aa,bb;
    double mi = 1000010;
    int h(int x,int y){
    	if(y==0)return x;
    	return h(y,x%y); 
    }
    int main(){
    	freopen("ratio.in","r",stdin);
    	freopen("ratio.out","w",stdout);
    	cin>>a>>b>>l;
    	for(int i=1;i<=l;i++){
    		for(int j=1;j<=l;j++){
    			if(i*1.0*b>=(a*1.0*j) && h(i,j)){
    				if((i*1.0/j-(a*1.0/b))<mi){
    					aa=i;
    					bb=j;
    					mi=i*1.0/j-(a*1.0/b);
    				}
    			}
    		}
    	}
    	cout<<aa<<" "<<bb;
    	return 0;
    }
    
    • 1
      @ 2023-8-14 12:08:26
      #include <cstdio>
      #include <iostream>
      using namespace std;
      int a, b, l, ka = 1000001, kb = 1;
      double c;
      inline int gcd(int a, int b) {
      	return !b ? a : gcd(b, a % b);
      } 
      int main() {
      	freopen("ratio.in", "r", stdin);
      	freopen("ratio.out", "w", stdout);
      	scanf("%d%d%d", &a, &b, &l);
      	c = double(a) / double(b);
      	for (int i = 1; i <= l; i++)
      	    for (int j = 1; j <= l; j++)
      	        if (gcd(i, j) == 1 && (double)i / (double)j >= c)
      	        	if ((double)i / (double)j < (double)ka / (double)kb)
      	        	    ka = i, kb = j;
      	printf("%d %d", ka, kb);
      	return 0;
      }
      
      • 1

      信息

      ID
      453
      时间
      1000ms
      内存
      256MiB
      难度
      6
      标签
      (无)
      递交数
      59
      已通过
      20
      上传者