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 题意: 若干条直线围城的湖,给定直线的端点,判断多少个转点会有危险?(危险是指直走的的话会掉进水里) ...
随机推荐
- PMP项目管理学习笔记(11)——范围管理之定义范围
定义范围过程组 定义范围包含将项目分解为团队成员要完成的具体工作之前你需要知道的所有一切. 输入:需求文档.项目章程.组织过程资产 工具:辅助工作室.产品分析.代理方案识别.专家判断 辅助工作室: 与 ...
- 秒杀Sublime Text的微软开源代码编辑工具Visual Studio Code
1. 下载链接: https://code.visualstudio.com/ 2. 秒开一个ASP.NET网站源码 3.编辑CSS颜色支持 4.Git支持 5.常用快捷键 Ctrl+Shift+P ...
- Spring AOP源码解析——专治你不会看源码的坏毛病!
昨天有个大牛说我啰嗦,眼光比较细碎,看不到重点.太他爷爷的有道理了!要说看人品,还是女孩子强一些. 原来记得看到一个男孩子的抱怨,说怎么两人刚刚开始在一起,女孩子在心里就已经和他过完了一辈子.哥哥们, ...
- (一) Docker in Docker
一. 背景介绍 工作中,要实现在docker中运行docker,实现镜像的拉取,创建,修改,上传等操作. 尝试过在docker中,安装docker.行不通,服务起不来. 而且直接在 docker 容 ...
- mybatis获取存储过程返回结果
获取存储过程返回结果 代码: // Map<String,Object> map = new HashMap<String,Object>(); map.put("i ...
- pagehelper 分页
分页jar包: <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pa ...
- Animate.css_css3动画库介绍
插件描述:Animate.css内置了很多典型的css3动画,兼容性好使用方便. Animate.css是一个有趣的,跨浏览器的css3动画库.很值得我们在项目中引用. 用法 1.首先引入animat ...
- zk伪集群部署
jdk 配置 # tar xf jdk-8u161-linux-x64.tar.gz -C /usr/local/ # vim /etc/profile.d/jdk.sh export JAVA_HO ...
- vue-cli中添加使用less
在vue-cli中构建的项目是可以使用less的,但是查看package.json可以发现,并没有less相关的插件,所以我们需要自行安装. 第一步:安装 npm install less less- ...
- POJ-1190-生日蛋糕(深搜,剪枝)
生日蛋糕 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23049 Accepted: 8215 Description 7月1 ...