您的位置:首页 > 其它

POJ 3039 搜索??? (逼近)

2016-10-27 19:54 246 查看

思路:
抄的题解

这叫搜索?

难以理解

我觉得就是枚举+逼近

//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\n",recx,recy);
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: