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());
        }
    }
} 
时间: 2024-08-01 05:07:44

CodeForces 592C The Big Race的相关文章

CodeForces 48C D - The Race

每个加油的站可以确定一个alpha的上下界,取最大的下界,取最下的上界,看看两者之间的满足条件的下一个加油站是否唯一. 因为可以用分数,所有就没用double了 #include<bits/stdc++.h> using namespace std; typedef long long ll; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; } struct Fra { ll p,q; Fra(ll x = 0,ll y = 1):p(x),q(y){ n

从《楼房重建》出发浅谈一类使用线段树维护前缀最大值的算法

首先需要申明的是,真的是浅谈,因为我对这个算法的认识还是非常低的. 既然是从<楼房重建>出发,那么当然是先看看这道题: [清华集训2013]楼房重建 bzoj 链接 题意简述: 有 \(n\) 栋楼,第 \(i\) 栋的高度为 \(H_i\),也就是说第 \(i\) 栋楼可以抽象成一条两端点为 \((i, 0)\) 和 \((i, H_i)\) 的线段. 初始时 \(H_i\) 均为 \(0\),要支持动态修改单点的 \(H_i\). 每次询问从 \(O(0, 0)\) 点可以看到多少栋楼房.

Codeforces 48C The Race 模拟题

题目链接:点击打开链接 题意: 给定n个加油站,一辆车由A点跑到B点,每个100m有一个加油站,每开100m需要10升油. 在每个车站会检查一下油量,若车子若开不到下一个加油站则加x升油. 开始有x升油 下面给出加油的记录. 问下一次加油在哪一站.若答案唯一输出具体哪站. 油箱容量无限 思路: 水模拟.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>

[2016-04-01][codeforces][659D][Bicycle Race]

时间:2016-04-01 19:10:24 星期五 题目编号:[2016-04-01][codeforces][659D][Bicycle Race] 题目大意:绕着海岸线行走,每次行走方式为上下左右,最后回到终点,在转弯的地方如果不及时转弯就会掉到水里,问有多少个地方可能掉到水里 分析: 可以发现,在内角为270°的地方才有可能掉到水里,设这样的地方有x个,则内角和 180 * (n - 2) = 270 * x + (n - x) * 90,得到 x = n?42n?42 #include

Codeforces 659D Bicycle Race

Codeforces 659D Bicycle Race Description:自行车每次行走都只有四个方向上,下,左,右:如果内角大于等于270度,自行车就会掉海里. 骑自行车旅行,第一个点为起点坐标,最后一个点还是起点坐标(表示自行车绕了一圈又回来了),问在骑行过程中总共掉海里几次? 呐.拿过来居然不会.果然还是窝太弱了. Solution: 1. 朴素. 叉积:看两个向量夹角,如果夹角小于90度,则直走的话会掉进水里. 1 #include<cstdio> 2 const int ma

[ An Ac a Day ^_^ ] CodeForces 659D Bicycle Race 计算几何 叉积

问有多少个点在多边形内 求一遍叉积 小于零计数就好了~ 1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 #include<math.h> 5 #include<string.h> 6 #include<string> 7 #include<map> 8 #include<set> 9 #include<vector>

CodeForces - 404B(模拟题)

Marathon Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose

Codeforces Round #346 (Div. 2) (659A,659B,659C,659D(几何叉乘),659E(并查集))

Round House 题目链接: http://codeforces.com/problemset/problem/659/A 解题思路: The answer for the problem is calculated with a formula ((a?-?1?+?b)  n + n)  n + 1. Such solution has complexity O(1). There is also a solution with iterations, modelling every o

Codeforces工具总结

本总结针对Linux用户,由于笔者一直使用Ubuntu系统打Codeforces 打Codeforcecs,想精确能力,打出究极罚时,可以考虑以下套餐 套餐一 vim选手 使用vim + fish + cf tool 套餐二 任意IDE选手 使用任意IDE + cf tool + 任意富文本编辑器(首推vscode) 富文本编辑器用于寻找模板和提交代码 IDE用于手敲代码 套餐三 CLion选手 使用CLion + Jhelper + 任意富文本编辑器 cf tool 使用指南 github地址