2017-5-14 湘潭市赛 Strange Optimization
Strange Optimization
Accepted : Submit :
Time Limit : MS Memory Limit : KB Strange Optimization Bobo is facing a strange optimization problem. Given n,m, he is going to find a real number α such that f(+α) 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. ≤n,m≤
The number of tests cases does not exceed . Output For each case, output a fraction p/q which denotes the result.
Sample Input Sample Output /
/ Note For the first sample, α= maximizes the function. Source
XTU OnlineJudge /**
题目:Strange Optimization
链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1268
题意:如题目所述。
思路:
f(1/2+a) ,a可以为任意实数,所以实际上等价于f(a); a为任意实数; i/n - j/m = (m*i-n*j)/(n*m); 分子看上去像是一个ax+by=c这样的式子,也就是x,y有解(i,j都为整数),那么c一定是gcd(a,b)的倍数。 所以m*i-n*j = k*gcd(n,m); k为整数。原式转化为 min |k*d/(n*m) + a| 中的最大值。令Xk=k*d/(n*m) 那么相邻两个结果之间的距离为Xk+1-Xk=d/(n*m), 问题转化为a这个位置到最近的Xk(k为整数)的距离要最大,a应该为Xk+1,Xk(k为整数)的中间位置,这样a到最近的Xk(k为整数)距离最大为d/(2*n*m)。 ans = 1/(2*n*m/gcd(n,m)) ; */ #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const int maxn = 1e5+;
LL gcd(LL a,LL b)
{
return b==?a:gcd(b,a%b);
}
int main()
{
LL n, m;
while(scanf("%I64d%I64d",&n,&m)==)
{
printf("1/%I64d\n",n/gcd(n,m)*m*);
}
return ;
}
2017-5-14 湘潭市赛 Strange Optimization的更多相关文章
- Gitlab一键端的安装汉化及问题解决(2017/12/14目前版本为10.2.4)
Gitlab的安装汉化及问题解决 一.前言 Gitlab需要安装的包太TM多了,源码安装能愁死个人,一直出错,后来发现几行命令就装的真是遇到的新大陆一样... ... 装完之后感觉太简单,加了汉化补丁 ...
- Strange Optimization(扩展欧几里得)
Strange Optimization Accepted : 67 Submit : 289 Time Limit : 1000 MS Memory Limit : 65536 KB Str ...
- hdu6212[区间dp] 2017青岛ACM-ICPC网络赛
原题: BZOJ1032 (原题数据有问题) /*hdu6212[区间dp] 2017青岛ACM-ICPC网络赛*/ #include <bits/stdc++.h> using name ...
- 2017.07.14【NOIP提高组】模拟赛B组
Summary 这次比赛因为迟到了,少了很多时间,也受到了相应的惩罚,这是好的,是个标记牌,警醒着我.这次比赛的题目很难,也就是说,大家的得分都很低,总的来说,收获还是很大的,因为有非常多的技巧被掌握 ...
- 2017 ACM-ICPC西安网赛B-Coin
B-Coin Bob has a not even coin, every time he tosses the coin, the probability that the coin's front ...
- Codeforces 801 A.Vicious Keyboard & Jxnu Group Programming Ladder Tournament 2017江西师大新生赛 L1-2.叶神的字符串
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 2017 icpc 南宁网络赛
2000年台湾大专题...英语阅读输入输出专场..我只能说很强势.. M. Frequent Subsets Problem The frequent subset problem is define ...
- 2017 icpc 沈阳网络赛
cable cable cable Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 2017.10.14 Java的流程控制语句switch&&随机点名器
今日内容介绍 1.流程控制语句switch 2.数组 3.随机点名器案例 ###01switch语句解构 * A:switch语句解构 * a:switch只能针对某个表达式的值作 ...
随机推荐
- ftrace
下面是一些关于ftrace的博文: ftrace 简介(IBM) 使用 ftrace 调试 Linux 内核 第 1 部分 第 2 部分 第 3 部分 Android系统性能调优工具介绍
- Android2017最新面试题(3-5年经验个人面试经历)
2017最新Android面试题 大家好,在跟大家讲述自己的面试经历,以及遇到的面试题前,先说说几句题外话. 接触Android已经3年,在工作中遇到疑难问题总是在网上(csdn大牛博客,stacko ...
- Hadoop之Azkaban详解
工作流调度器azkaban1 为什么需要工作流调度系统 1)一个完整的数据分析系统通常都是由大量任务单元组成:shell脚本程序,java程序,mapreduce程序.hive脚本等 2)各任务单元之 ...
- java使用freemarker作为模板导出Excel表格
1:首先新建一个excel表格自己弄好格式如下图 2:把excel 表格另存为xml格式文件如下图 3:这个时候的文件就是xml 格式的文件了,在myeclipse里面项目工程里面新建一个文件后缀为. ...
- SpringBoot修改默认端口号
SpringBoot修改默认端口号 server.port=8088 学习了:https://blog.csdn.net/zknxx/article/details/53433592 java -ja ...
- 【原】Ubuntu下使用teamviewer
想尝试直接使用Xmanager打开Ubuntu桌面版,结果一直存在问题,迂回一下,尝试使用teamviewer解决,结果OK.办法如下: 在Ubuntu中,下载teamviewer,通过Windows ...
- lodash toString 转换为字符串
转换 value 为字符串. null 和 undefined 将返回空字符串.-0 将被转换为字符串"-0". _.toString(null); // => '' _.t ...
- POSTGRESQL同步——SLONY-I配置
来自:http://bbs.chinaunix.net/thread-955564-1-1.html 参考文档 http://bbs.chinaunix.net/viewthr ... page%3D ...
- 51单片机 | SPI协议与应用实例
———————————————————————————————————————————— SPI总线 - - - - - - - - - - - - - - - - - - - - - - - - - ...
- Vue 全家桶 + Electron 开发的一个跨三端的应用
代码地址如下:http://www.demodashi.com/demo/11738.html GitHub Repo:vue-objccn Follow: halfrost · GitHub 利用 ...