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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Strange Optimization(扩展欧几里得)

發(fā)布時間:2024/4/14 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Strange Optimization(扩展欧几里得) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Strange Optimization

Accepted : 67?Submit : 289
Time Limit : 1000 MS?Memory Limit : 65536 KB

?

Strange Optimization

Bobo is facing a strange optimization problem. Given n,m?, he is going to find a real number α?such that f(12+α)?is maximized, where f(t)=mini,jZ|in?jm+t|?. Help him!

Note: It can be proved that the result is always rational.

Input

The input contains zero or more test cases and is terminated by end-of-file.

Each test case contains two integers n,m?.

  • 1n,m109
  • The number of tests cases does not exceed 104?.

Output

For each case, output a fraction p/q?which denotes the result.

Sample Input

1 1 1 2

Sample Output

1/2 1/4

Note

For the first sample, α=0?maximizes the function

?

?

//題意還是很好懂的,只要明白擴展歐幾里得原理,這題很簡單,i/n - j/m 可以化為 ( mi - nj ) / ( n * m )

因為 i,j 為整數(shù)所以等于? k*gcd(n,m)/(n*m)

所以 f(t)的最大值為 1 / ( Lcm(n,m)*2 )

1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <algorithm> 5 using namespace std; 6 #define LL long long 7 8 LL gcd(LL a,LL b) 9 { 10 return b==0?a:gcd(b,a%b); 11 } 12 13 int main() 14 { 15 LL n,m; 16 while (scanf("%I64d%I64d",&n,&m)!=EOF) 17 { 18 LL p = gcd(n,m); 19 LL q = n*m*2; 20 LL yue = gcd(p,q); 21 printf("%I64d/%I64d\n",p/yue,q/yue); 22 } 23 return 0; 24 } View Code

?

轉載于:https://www.cnblogs.com/haoabcd2010/p/6861733.html

總結

以上是生活随笔為你收集整理的Strange Optimization(扩展欧几里得)的全部內容,希望文章能夠幫你解決所遇到的問題。

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