xtu 1268 Strange Optimization 湘潭邀请赛I

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 thatf(12+α) is maximized, where f(t)=mini,jZ|injm+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通分,得出

 得出(i*m-j*n)/n*m   然后显然可以提出gcd(n,m)因子
就相当于是k*gcd(n,m)/n*m,k为整数,就是个等差数列,然后就相当于去找符合条件的首项,那么由于是绝对值,,不用考虑最小边界的问题,那么容易得出首项为二分之一公差答案,然后把答案化到最简就行了,
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<iostream>
#include<sstream>
#define LL long long
using namespace std;
LL gcd(LL a,LL b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    LL n,m;
    while(~scanf("%lld%lld",&n,&m))
    {
        LL d = gcd(n,m);
        LL d2  = gcd(d,2*n*m);
        cout<<1<<'/'<<2*m*n/d2<<endl;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值