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的更多相关文章

  1. Gitlab一键端的安装汉化及问题解决(2017/12/14目前版本为10.2.4)

    Gitlab的安装汉化及问题解决 一.前言 Gitlab需要安装的包太TM多了,源码安装能愁死个人,一直出错,后来发现几行命令就装的真是遇到的新大陆一样... ... 装完之后感觉太简单,加了汉化补丁 ...

  2. Strange Optimization(扩展欧几里得)

    Strange Optimization Accepted : 67   Submit : 289 Time Limit : 1000 MS   Memory Limit : 65536 KB Str ...

  3. hdu6212[区间dp] 2017青岛ACM-ICPC网络赛

    原题: BZOJ1032 (原题数据有问题) /*hdu6212[区间dp] 2017青岛ACM-ICPC网络赛*/ #include <bits/stdc++.h> using name ...

  4. 2017.07.14【NOIP提高组】模拟赛B组

    Summary 这次比赛因为迟到了,少了很多时间,也受到了相应的惩罚,这是好的,是个标记牌,警醒着我.这次比赛的题目很难,也就是说,大家的得分都很低,总的来说,收获还是很大的,因为有非常多的技巧被掌握 ...

  5. 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 ...

  6. 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 ...

  7. 2017 icpc 南宁网络赛

    2000年台湾大专题...英语阅读输入输出专场..我只能说很强势.. M. Frequent Subsets Problem The frequent subset problem is define ...

  8. 2017 icpc 沈阳网络赛

    cable cable cable Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  9. 2017.10.14 Java的流程控制语句switch&&随机点名器

    今日内容介绍 1.流程控制语句switch 2.数组 3.随机点名器案例 ###01switch语句解构     * A:switch语句解构       * a:switch只能针对某个表达式的值作 ...

随机推荐

  1. 在GIT中修改提交记录

    在SVN中,提交记录是无法修改的.比如说,当我们提交了某次修改后,发现该次提交中有错误时,只能将将补丁再次提交一遍.这样,就存在两次提交记录,没有保证提交的原子性. 在GIT中,由于提交是在本地进行的 ...

  2. winfrom GDI知识

     c#使用GDI+简单绘图 http://blog.csdn.net/smartsmile2012/article/details/30255303 NET3.5 GDI+ 图形操作1 http:// ...

  3. gcc static静态编译选项提示错误:/usr/lib/ld:cannot find -lc

    在学习gcc静态库动态库编译的时候选用静态库编译时出错显示:/usr/lib/ld:cannot find -lc 百度:/usr/lib/ld:cannot find -lc多处给的解决方案为: 然 ...

  4. Simple JavaScript Inheritance(John Resig)

    I’ve been doing a lot of work, lately, with JavaScript inheritance – namely for my work-in-progress ...

  5. http://www.360doc.com/content/12/0516/14/1671317_211422841.shtml

    http://www.360doc.com/content/12/0516/14/1671317_211422841.shtml

  6. Python Xpath 提取html整个元素(标签与内容)

    提取html某标签中文字时,文字中含有:“<sub>2</sub>O<sub>5</sub>”,导致提取的文字不符合预期. 解决方法: #coding= ...

  7. Netty4详解三:Netty架构设计(转)

    http://blog.csdn.net/suifeng3051/article/details/28861883?utm_source=tuicool&utm_medium=referral ...

  8. &lt;LeetCode OJ&gt; 101. Symmetric Tree

    101. Symmetric Tree My Submissions Question Total Accepted: 90196 Total Submissions: 273390 Difficul ...

  9. 在 Word 中的受支持的区域设置标识符的列表

    这篇文章包含当前可用的区域设置 ID (LCID) 语言代码的列表.   概要 这篇文章包含当前可用的区域设置 ID (LCID) 语言代码的列表. 区域设置 ID (LCID): 由 Microso ...

  10. node - 导包机制

    在学node js的时候,经常各种导包 let http = require('http'); 然后它的运行机制: 1. 查找当前目录下面的node_modules 2. 全局查找(首先添加到path ...