2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:I— Strange Optimization
题目链接:传送门
Strange Optimization
Bobo is facing a strange optimization problem. Given n,m , he is going to find a real number α such that f(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 1 1 2
Sample Output
1/2 1/4
Note
For the first sample, α=0 maximizes the function.
解题思路:f(t) = 1/Icm(n,m)*2
|i/n-j/m|所能表示的最小值为1/Icm(n,m),令其为p,当t>=p,f(t)=0。当t<p,只有t=p/2时,f(t)才能取到最大值p/2。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
using namespace std;
typedef __int64 ll;
const int N = 100100;
const int M = 20;
const int INF = 0x3fffffff;int gcd( int a , int b )
{if( b == 0 ) return a;else return gcd( b , a%b );
}int main()
{ll n,m;while( ~scanf("%I64d%I64d",&n,&m) ){ll p = n/gcd(n,m)*m*2;printf("%d/%I64d\n",1,p);}return 0;
}
2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:I— Strange Optimization相关推荐
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛 Highway
Highway Accepted : 122 Submit : 393 Time Limit : 4000 MS Memory Limit : 65536 KB Highway In ICPC ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛 Partial Sum
Partial Sum Accepted : 124 Submit : 450 Time Limit : 3000 MS Memory Limit : 65536 KB Partial Su ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛 Strange Optimization
Strange Optimization Accepted : 89 Submit : 350 Time Limit : 1000 MS Memory Limit : 65536 KB St ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:H—Highway
题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1267 Highway In ICPCCamp there wer ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:E—Partial Sum
题目链接:传送门 Partial Sum Bobo has a integer sequence a1,a2,-,an of length n . Each time, he selects t ...
- XTU 1264 Partial Sum 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)
Partial Sum Accepted : 87 Submit : 366 Time Limit : 3000 MS Memory Limit : 65536 KB Partial Su ...
- xtu 1268 Strange Optimization 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)
Strange Optimization Bobo is facing a strange optimization problem. Given n,m , he is going to find ...
- XTU 1268 Strange Optimization 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)
Strange Optimization Accepted : 65 Submit : 286 Time Limit : 1000 MS Memory Limit : 65536 KB S ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南) 暨 第九届湘潭市大学生程序设计比赛H.Highway(树的直径)
Highway Accepted : 122 Submit : 393 Time Limit : 4000 MS Memory Limit : 65536 KB Highway In ICPC ...
最新文章
- ROS学习笔记—-- catkin
- Android镜像文件的拆解
- 【BLE】TI CC2640R2F片内OAD实验
- 5、Power Map—实例:填充地图
- linux是数据库软件么,什么是适用于Linux的良好数据库ERD工具?
- java axmlprinter_安卓xml配置文件解析工具-AXMLPrinter2.jar(androidmanifest.xml 反编译)下载官方最新版-西西软件下载...
- Permissions for id_rsa are too open
- rlwrap解决sqlplus上下键和backspace键找历史命令
- 一个简单的mysql服务检测启动脚本
- OpenDrive学习笔记
- paint.net ps证件照背景色
- 在线头像制作网站FaceYourManga
- 雷霆战机服务器维护公告,雷霆战机停服公告 4月11日服务器维护
- python缺失值处理 fillna_python 处理缺失值
- maven的jar包引入成功却仍然爆红
- 数据库查询时报错com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: ‘1.7725000000E10‘ in column ‘17‘ is outs
- 浅谈MySQL中优化sql语句查询常用的30种方法
- goto在golang中的用法
- 天才如周杰伦与周星驰也难逃孤独
- 狼人杀个人理解玩法之(守卫)