Strange Optimization | ||
Accepted : 67 | Submit : 289 | |
Time Limit : 1000 MS | Memory Limit : 65536 KB |
Strange OptimizationBobo is facing a strange optimization problem. Given n,m , he is going to find a real number α such thatf(12+α) is maximized, where f(t)=mini,j∈Z|in−jm+t| . Help him! Note: It can be proved that the result is always rational. InputThe input contains zero or more test cases and is terminated by end-of-file. Each test case contains two integers n,m .
OutputFor each case, output a fraction p/q which denotes the result. Sample Input1 1 1 2 Sample Output1/2 1/4 NoteFor the first sample, α=0 maximizes the function 题目大意 题目给你一个函数,让你求每一段值域最小值中的最大值 思路 首先根据我们数学的直觉,会先把i/n-j/m通分,得出
得出(i*m-j*n)/n*m 然后显然可以提出gcd(n,m)因子
就相当于是k*gcd(n,m)/n*m,k为整数,就是个等差数列,然后就相当于去找符合条件的首项,那么由于是绝对值,,不用考虑最小边界的问题,那么容易得出首项为二分之一公差答案,然后把答案化到最简就行了,
代码:
|