xtu 1268 Strange Optimization 湘潭邀请赛I
来源:互联网 发布:godaddy免费域名 编辑:程序博客网 时间:2024/06/11 17:26
Strange Optimization
Accepted : 67 Submit : 289Time 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,j∈Z|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 .
- 1≤n,m≤109
- 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 11 2
Sample Output
1/21/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 longusing 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
- xtu 1268 Strange Optimization 湘潭邀请赛I
- xtu 1268 Strange Optimization 湘潭邀请赛I
- 【XTU】2016湘潭邀请赛 I Substring Query【AC自动机+分块】
- XTU 1268 Strange Optimization 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)
- xtu 1268 Strange Optimization 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)
- 豪杰信息杯I 湘潭oj1268-Strange Optimization
- 2016湘潭邀请赛 XTU 1243 2016
- xtu 1266 Parentheses 2017湘潭邀请赛G
- xtu 1267 Highway 湘潭邀请赛H
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:I— Strange Optimization
- 2016湘潭邀请赛 xtu 1243 矩阵快速幂
- xtu 1264 Partial Sum 2017湘潭邀请赛E
- XTU 1203 A simple problem (2014 湖南湘潭邀请赛 A题)(数学)
- 17-JSCPC&&CCPC中南赛区 I-Strange Optimization-数学
- ACM_ICPC 湘潭邀请赛
- 湘潭邀请赛总结
- 湘潭邀请赛A
- 2015湘潭邀请赛小记
- MATLAB笔记 sparse稀疏矩阵函数
- 深入了解jQuery之整体架构
- bzoj 2795: [Poi2012]A Horrible Poem hash
- linux下bin安装包制作教程
- Activity四种启动模式
- xtu 1268 Strange Optimization 湘潭邀请赛I
- python 多线程
- java中验证18位身份证的正则表达式
- input搜索筛选\过滤列表
- (转)jQuery中的extend()方法
- const与static关键字
- service的onStartCommand
- Unity与iOS相互调起、交互
- yv12、I420、nv12、nv21相互转换