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 题意: 若干条直线围城的湖,给定直线的端点,判断多少个转点会有危险?(危险是指直走的的话会掉进水里) ...
随机推荐
- 全文索引Elasticsearch,Solr,Lucene
最近项目组安排了一个任务,项目中用到了全文搜索,基于全文搜索 Solr,但是该 Solr 搜索云项目不稳定,经常查询不出来数据,需要手动全量同步,而且是其他团队在维护,依赖性太强,导致 Solr 服务 ...
- MMRecovery下载和恢复方法教程
如何能下载到最新版本的恢复软件MMRecovery?下载后我们如何能够快速的使用起来呢?好的,我们接下来就开始这些内容. 一.下载最新版本的恢复软件MMRecovery 1.官方网站下载,如下图在浏览 ...
- Android(java)学习笔记175:Android进程间通讯(IPC)之AIDL
一.IPC inter process communication 进程间通讯 二.AIDL android interface defination language 安卓接口定义语言 满 ...
- Linux基础命令——查看进程命令
linux是一个 多进程 多用户的操作系统 ps(显示当前进程的状态) ps -ef 查看当前linux 进程 ps -ef | grep 'mysqld' 过滤mysql的进程 (grep ...
- react中的jsx详细理解
这是官网上的一个简单的例子 const name = 'Josh Perez'; const element = <h1>Hello, {name}</h1>; ReactDO ...
- 串的基本操作(KMP算法实现)
#include <iostream> #include <math.h> using namespace std; void StrAssign(char *T) { cha ...
- STM32--TIM定时器时钟分割(疑难)
不太明白 (1) TIM_Perscaler来设置预分频系数: (2) TIM_ClockDivision来设置时钟分割(时钟分频因子): (3) TIM_C ...
- [BZOJ 3823]定情信物
题面 定情信物 题解 这题主要考高中物理和数学. 首先定义 \(f[i][j]\) 表示 \(i\) 维超立方体中第 \(j\) 维元素的数量,根据实际意义,我们可以推出递推式: \(f[i][j]= ...
- Shell脚本问题详解
例1:找出当前系统中端口大于1024的程序! 使用netstat -tuln查询出的结果如下,需要输出红色字体的行: [root@localhost ~]# netstat -tuln Active ...
- 使用 wsgiref 创建WSGI APP
wsgify装饰器将一个普通函数转变成WSGI应用程序. class webob.dec.wsgify(func=None, RequestClass=None, args=(), kwargs=No ...