Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm
C. The Big Race
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/592/problem/C
Description
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?
Input
The first line of the input contains three integers t, w and b (1 ≤ t, w, b ≤ 5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.
Output
Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1, that both p and q are divisible by d.
Sample Input
Sample Output
3/10
HINT
题意
终点可以在1-t里面随便选择一个
终点之后都是陷阱,然后有两个人在比赛,一个人一步走w米,一个人一步走b米,谁能不越过终点的情况,走的最远,就算谁赢
然后问你选择平等的概率是多少
题解:
找规律,找规律
对于每个lcm我们可以当成新的一轮是吧,然后每个lcm中,我们可以选择min(w,b)个,作为起点
然后我们搞一搞就好了
这儿唯一遇到的情况就是,当lcm(w,b)> t的时候,这时候就应该输出min(w,b)-1/t
但是我们怎么判断lcm(w,b)>t呢?log(a*1.0) + log(b * 1.0) - log( gcd(a,b)*1.0 )> log (c * 1.0)就好了
代码
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
long long t,w,b;
long long gcd(long long a,long long b)
{
return b==?a:gcd(b,a%b);
}
long long lcm(long long a,long long b)
{
return a/gcd(a,b)*b;
}
int check(long long a,long long b,long long c)
{
if(log(a*1.0) + log(b * 1.0) - log( gcd(a,b)*1.0 )> log (c * 1.0))
return ;
return ;
} int main()
{
cin>>t>>w>>b;
if(w==b)
{
printf("1/1");
return ;
}
long long ans1,ans2=t;
if(check(w,b,t))
{
ans1 = min(w-,min(b-,t));
}
else
{
long long kkk = lcm(w,b);
long long ggg = t / kkk;
long long Ans1;
if(ggg * kkk + min(w,b) <= t)
Ans1 = (ggg + )* min(w,b) - ;
else
Ans1 = ggg * ( min(w,b) - kkk ) + t;
ans1 = Ans1;
}
printf("%lld/%lld",ans1/gcd(ans1,ans2),ans2/gcd(ans1,ans2));
}
Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm的更多相关文章
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #328 (Div. 2) D. Super M
题目链接: http://codeforces.com/contest/592/problem/D 题意: 给你一颗树,树上有一些必须访问的节点,你可以任选一个起点,依次访问所有的必须访问的节点,使总 ...
- Codeforces Round #328 (Div. 2) D. Super M 虚树直径
D. Super M Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/D ...
- Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学
B. The Monster and the Squirrel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...
- Codeforces Round #328 (Div. 2) A. PawnChess 暴力
A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...
- Codeforces Round #328 (Div. 2)
这场CF,准备充足,回寝室洗了澡,睡了一觉,可结果... 水 A - PawnChess 第一次忘记判断相等时A先走算A赢,hack掉.后来才知道自己的代码写错了(摔 for (int i=1; ...
- Codeforces Round #328 (Div. 2)_B. The Monster and the Squirrel
B. The Monster and the Squirrel time limit per test 1 second memory limit per test 256 megabytes inp ...
随机推荐
- QuartZ Cron表达式在java定时框架中的应用
CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表. CronT ...
- Delphi Waring 的信息
Display PreferencesWarning messages (Delphi)Go Up to Delphi Compiler Directives (List) Index TypeSwi ...
- sharepoint2010 创建自定义列表
转:http://boke.25k5.com/kan77298.html 如何创建自定义列表 首先了解创建自定义列表中涉及到的几个名词:栏.内容类型. ①栏:栏即列.字段(Field),MSDN中给出 ...
- hdu 3938 Portal(并查集+离线+kruskal)2011 Multi-University Training Contest 10
搜了题解才把题搞明白.明白之后发现其实题意很清晰,解题思路也很清晰,只是题目表述的很不清晰…… 大意如下—— 给你一个无向图,图中任意两点的距离是两点间所有路径上的某一条边,这条边需要满足两个条件:1 ...
- Dubbo入门实例--转载
原文地址:http://blog.csdn.net/ruishenh/article/details/23180707?utm_source=tuicool 1. 概述 Dubbo是一个分布式服务 ...
- Winform之SpreadSheetGear转DevExpress.XtraSpreadsheet.v13.2 z
DevExpress.XtraSpreadsheet.v13.2 允许用户创建.管理.打印.转换spreadsheet文件而不需要用户安装Office. 什么是Spreadsheet 可以看到最后就是 ...
- An Oblivious Watermarking for 3-D Polygonal Meshes Using Distribution of Vertex Norms
An Oblivious Watermarking for 3-D Polygonal Meshes Using Distribution of Vertex Norms 转眼就11月底了,突然开始有 ...
- offsetWidth、offsetleft 等图文详解
网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...
- nodejs写的一个网页爬虫例子(坏链率)
因为工作需要,用nodejs写了个简单的爬虫例子,之前也没用过nodejs,连搭环境加写大概用了5天左右,so...要多简陋有多简陋,放这里给以后的自己看~~ 整体需求是:给一个有效的URL地址,返回 ...
- Spark系列(五)Master主备切换机制
Spark Master主备切换主要有两种机制,之中是基于文件系统,一种是基于Zookeeper.基于文件系统的主备切换机制需要在Active Master挂掉后手动切换到Standby Master ...