CodeForces 592C The Big Race
公倍数之间的情况都是一样的,有循环节。
注意min(a,b)>t的情况和最后一段的处理。C++写可能爆longlong,直接Java搞吧......
import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Scanner; public class Main { public static BigInteger GCD(BigInteger a,BigInteger b)
{
if(b.compareTo(BigInteger.ZERO)==0) return a;
return GCD(b,a.remainder(b));
} public static BigInteger MIN(BigInteger a,BigInteger b)
{
if(a.compareTo(b)>=0) return b;
return a;
} public static void main(String[] args) {
Scanner sc = new Scanner (new BufferedInputStream(System.in)); BigInteger t=sc.nextBigInteger();
BigInteger a=sc.nextBigInteger();
BigInteger b=sc.nextBigInteger(); if(MIN(a,b).compareTo(t)>0)
{
System.out.print("1"+"/"+"1");
}
else{
BigInteger gcd=GCD(a,b);
BigInteger lcm=a.multiply(b).divide(gcd);
BigInteger k=MIN(a,b).subtract(BigInteger.ONE);
BigInteger ans=BigInteger.ZERO;
BigInteger tmp=t.divide(lcm);
ans=k;
if(tmp.compareTo(BigInteger.ZERO)>0)
{
BigInteger u=tmp.subtract(BigInteger.ONE);
ans=ans.add(u.multiply(k.add(BigInteger.ONE)));
ans=ans.add(BigInteger.ONE);
ans=ans.add(MIN(k,t.subtract(lcm.multiply(tmp))));
}
BigInteger fz=ans;
BigInteger fm=t;
BigInteger e=GCD(fz,fm);
fz=fz.divide(e);
fm=fm.divide(e);
System.out.print(fz.toString()+"/"+fm.toString());
}
}
}
CodeForces 592C The Big Race的更多相关文章
- codeforces 659D D. Bicycle Race(水题)
题目链接: D. Bicycle Race time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #438 B. Race Against Time
Description Have you ever tried to explain to the coordinator, why it is eight hours to the contest ...
- CodeForces 48C D - The Race (Fraction,数学)
每个加油的站可以确定一个alpha的上下界,比如,第i次加油站a[i],前面加了i次油,a[i]*10≤ alpha*i <(a[i]+1)*10. 取最大的下界,取最小的上界,看看两者之间的满 ...
- Codeforces Round #131 (Div. 2) E. Relay Race dp
题目链接: http://codeforces.com/problemset/problem/214/E Relay Race time limit per test4 secondsmemory l ...
- 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/probl ...
- Codeforces Round #346 (Div. 2) D Bicycle Race
D. Bicycle Race 题目链接http://codeforces.com/contest/659/problem/D Description Maria participates in a ...
- Codeforces Round #346 (Div. 2) D. Bicycle Race 叉积
D. Bicycle Race 题目连接: http://www.codeforces.com/contest/659/problem/D Description Maria participates ...
- CodeForces 659D Bicycle Race (判断点是否为危险点)
D - Bicycle Race Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- Codeforces 659D Bicycle Race【计算几何】
题目链接: http://codeforces.com/contest/659/problem/D 题意: 若干条直线围城的湖,给定直线的端点,判断多少个转点会有危险?(危险是指直走的的话会掉进水里) ...
随机推荐
- Database coalesce
coalesce 语法 注意:连接操作符“||”是一个值得注意的例外. 例如,空值加任何值都是空值,空值 乘任何值也都是空值,依此类推. 参数 expression 任何类型的表达式. n 表示可以指 ...
- 如何使用capedit分割数据包文件
wireshark是一个网络数据包的分析工具,主要用来捕获网卡上的数据包并显示数据包的详细内容.在处理一些大的数据包文件时,如果直接用wireshark图形工具打开一些大文件的数据包会出现响应慢甚至没 ...
- (转)SpringMVC学习(十)——SpringMVC与前台的json数据交互
http://blog.csdn.net/yerenyuan_pku/article/details/72514022 json数据格式在接口调用中.html页面中比较常用,json格式比较简单,解析 ...
- CAD交互绘制圆弧(网页版)
在CAD设计时,需要绘制圆弧,用户可以在图面点圆弧起点,圆弧上的一点和圆弧的终点,这样就绘制出圆弧. 主要用到函数说明: _DMxDrawX::DrawArc2 由圆弧上的三点绘制一个圆弧.详细说明如 ...
- Activiti6简明教程
一.为什么选择Activiti 工作流引擎对比 二.核心7大接口.28张表 7大接口 (一)7大接口 RepositoryService:提供一系列管理流程部署和流程定义的API. RuntimeSe ...
- PHP12 文件操作
学习要点 文件系统概述 目录基本操作 文件基本操作 文件上传下载 文件上传类的设计 文件系统概述 概述 PHP文件系统的操作是基于UNIX系统模型,所以有一些文件处理函数无法在windows服 ...
- 雷林鹏分享:Lua 数据类型
Lua是动态类型语言,变量不要类型定义,只需要为变量赋值. 值可以存储在变量中,作为参数传递或结果返回. Lua中有8个基本类型分别为:nil.boolean.number.string.userda ...
- 「 HDOJ P3887 」 Counting Offspring
翻译 题目描述 给你一棵树,和它的树根 $P$,并且节点从 $1\rightarrow n$ 编号,现在定义 $f(i)$ 为 $i$ 的子树中,节点编号小于 $i$ 的节点的个数. 输入格式 有多组 ...
- 使用SimpleDateFormat 将毫秒转换成时分秒 格式:HH:mm:ss
public static String dateFormatFromMilliSecond(long seconds) { //初始化format格式 SimpleDateFor ...
- Linux基础学习-Samba文件共享服务
使用Samba文件共享服务 Samba起源: 早期网络想要在不同主机之间共享文件大多要用FTP协议来传输,但FTP协议仅能做到传输文件却不能直接修改对方主机的资料数据,这样确实不太方便,于是便出现了N ...