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只能针对某个表达式的值作 ...
随机推荐
- Spring整合jdbc-jdbc模板对象
1,Spring 中封装了一个可以操作数据库的对象(JDBCTemplate:jdbc模板),这个对象封装了JDBC技术 2,与DBUtil中的QueryRunner对象非常相似 3,操作 (1)导包 ...
- TabHost
(一) 知识点:id使用系统自带 1.效果图: 2.布局 activity_main.xml <?xml version="1.0" encoding="utf-8 ...
- POP3、IMAP、SMTP邮件协议的理解
一个热爱技术的菜鸟...用点滴的积累铸就明日的达人 CSDN博客链接: http://blog.csdn.net/my_confesser 正文 今天入职配置OutLook的时候,看到公司的 ...
- 关于BOM UTF8
这三篇可以看下: http://www.zhihu.com/question/20167122 http://www.cnblogs.com/DDark/archive/2011/11/28/2266 ...
- linux中查找文件属于那个软件包的方法
一.linux中查找文件属于那个软件包的方法 [root@salt prod]# whereis htpasswdhtpasswd: /usr/bin/htpasswd /usr/share/man/ ...
- http://blog.csdn.net/jhg1204/article/details/45013987
http://blog.csdn.net/jhg1204/article/details/45013987
- 一起來玩鳥 Starling Framework(6)Juggler、Tween、以及DelayCall
這篇開始來講Starling裡的Animation.Juggle是個簡單的Class,用來控制動畫的進行.他負責管理經由add()加進來的實現IAnimatable介面的物件,然後當Juggler的a ...
- python 下载小说
以下载官场风月小说为例: 具体代码: # coding=utf-8 import os import re from selenium import webdriver from selenium.c ...
- 深入解析淘宝Diamond之客户端架构
转载:http://blog.csdn.net/u013970991/article/details/52088350 一.什么是Diamond diamond是淘宝内部使用的一个管理持久配置的系统, ...
- MonoDevelop 的一些设置
原地址:http://hi.baidu.com/next2_me MonoDevelop保存跳到顶部 Saving in MonoDevelop goes to the top line. MonoD ...