日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

bzoj1684[Usaco2005 Oct]Close Encounter*

發布時間:2023/12/20 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 bzoj1684[Usaco2005 Oct]Close Encounter* 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

bzoj1684[Usaco2005 Oct]Close Encounter

題意:

找一個分數它最接近給出一個分數。你要找的分數的分子分母的范圍在1..32767。

題解:

枚舉所求分數的分子,用其乘上給出分數得到一個浮點數分母,比較分母向上/下取整所得分數與答案比較。

代碼:

1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <cmath> 5 #define inc(i,j,k) for(int i=j;i<=k;i++) 6 #define maxn 10010 7 using namespace std; 8 9 inline int read(){ 10 char ch=getchar(); int f=1,x=0; 11 while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();} 12 while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); 13 return f*x; 14 } 15 int n,d,ansa,ansb; double ans; 16 int main(){ 17 n=read(); d=read(); ans=10; 18 inc(i,1,32767){ 19 int j=n*i/d,k=j+1; 20 if(fabs((double)k/(double)i-(double)n/(double)d)<ans) 21 ans=fabs((double)k/(double)i-(double)n/(double)d),ansa=k,ansb=i; 22 if(j*d!=n*i&&fabs((double)j/(double)i-(double)n/(double)d)<ans) 23 ans=fabs((double)j/(double)i-(double)n/(double)d),ansa=j,ansb=i; 24 } 25 printf("%d %d",ansa,ansb); return 0; 26 }

?

20160927

轉載于:https://www.cnblogs.com/YuanZiming/p/5966618.html

總結

以上是生活随笔為你收集整理的bzoj1684[Usaco2005 Oct]Close Encounter*的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。