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());}} }
转载于:https://www.cnblogs.com/zufezzt/p/5470217.html
CodeForces 592C The Big Race相关推荐
- Codeforces 671E Organizing a Race (贪心、线段树)
题目链接 https://codeforces.com/contest/671/problem/E 题解 完全不会做--基本是抄lk的代码 ruogu的题解: https://www.luogu.co ...
- CodeForces 48C D - The Race (Fraction,数学)
每个加油的站可以确定一个alpha的上下界,比如,第i次加油站a[i],前面加了i次油,a[i]*10≤ alpha*i <(a[i]+1)*10. 取最大的下界,取最小的上界,看看两者之间的满 ...
- Codeforces Round #438 B. Race Against Time
题意: 这题题意看了我好久,意思就是给你时针,分针,秒针,再给你一个起点和终点,起点和终点均为小于12的整数,问你能不能在钟上 从起点走到终点,而不越过指针. Examples Input 12 30 ...
- 【Codeforces】659D Bicycle Race(多边形内角和公式...)
题目大意(个人理解,有错请指出):环湖骑自行车 到拐点需要拐弯,如果到这个拐点不拐弯,沿着原来的方向继续骑,如果会掉到湖里,那么这个点是危险的,这样的点有多少个? 通过画图可以了解到,所有危险的点内角 ...
- office受保护视图_使用受保护的视图激发恶意Office文档
office受保护视图 介绍 (Intro) I wanted to share an interesting behavior I discovered with Microsoft Office ...
- Codeforces Round #346 (Div. 2) D. Bicycle Race 叉积
D. Bicycle Race 题目连接: http://www.codeforces.com/contest/659/problem/D Description Maria participates ...
- CodeForces 241F Race
题目大意 给定N*M个方格状的街区,其中包括: 若干建筑物,双向直线的道路以及交叉路口组成了TOC. 每个建筑物:占恰好的一个街区. 每条道路:所有道路的宽度都为1个街区,并且道路都是水平的或竖直的. ...
- Codeforces Round #101 (Div. 2)
C.Queue(模拟) C.Queue(模拟) TimeLimit:2000MSMemoryLimit:262144KB Time\quad Limit:2000MS\quad Memory\quad ...
- CodeForces 375D Tree and Queries
传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...
最新文章
- 2017.9.12.语文
- ZOJ3370. Radio Waves(2-sat)
- php检测目录,php检测文件目录大小类
- js实现鼠标拖拽功能基本思路
- [最短路/线段树大法优化DIJ] 【模板】单源最短路径(标准版)
- 提高WordPress访问速度与性能的技巧总结
- 吐血解决python中文写入文件问题
- python接口自动化(二十六)--批量执行用例 discover(详解)
- leetcode每日刷题计划-简单篇day6
- 为什么象网络蚂蚁这样的多线程程序可以加快下载速度?
- python调用按键精灵插件_按键精灵 插件命令 重中之重务必要记住怎么操作
- Python通过selenium操作edge浏览器
- 家用电器行业十二月行业动态报告:11月冰洗表现亮眼,空调价格回升持续(20201231).PDF
- Arduino 利用ADS1115 AD转换模块进行数据读取
- 安卓手机设置指定文件夹下的图片、视频不被相册读取到
- ⅰsee是什么意思_see是什么意思?
- 暾盛机器人_移动机器人视觉伺服.pdf
- 论文笔记(一):Temporal Network Embedding with High-Order Nonlinear Information
- 计算56除以四十可以用计算机,CPU如何来计算除法 一
- 如何使用Node.js来制作电子音乐-和弦