zoukankan      html  css  js  c++  java
  • POJ 3039 搜索??? (逼近)

    思路:
    抄的题解

    这叫搜索?

    难以理解

    我觉得就是枚举+逼近

    //By SiriusRen
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int n,recx,recy,x,y;
    int gcd(int a,int b){
        return b?gcd(b,a%b):a;
    }
    int main(){
        while(~scanf("%d%d",&x,&y)){
            double temp,a,minn=66666.666;
            a=(double)x/y;
            int n=x,m=y;
            x=y=1;
            while(x<=32767&&y<=32767){
                temp=(double)x/y;
                int p=gcd(x,y),dx=x/p,dy=y/p;
                if(abs(temp-a)<abs(minn-a)&&(!(dx==n&&dy==m)))
                    minn=temp,recx=dx,recy=dy;
                if(temp<a)x++;
                else y++;
            }
            printf("%d %d
    ",recx,recy);
        }
    }

    这里写图片描述

  • 相关阅读:
    20210420
    20210419
    2021041601
    20210416
    20210415
    20210414
    20210413
    20210412
    20210409
    20210405
  • 原文地址:https://www.cnblogs.com/SiriusRen/p/6532222.html
Copyright © 2011-2022 走看看