剩余系

Problem - I - Codeforces

题意

给定 \(H,M,A\)

\(2<=H,M<=10^9,\;0<=A<=\frac {H*M}2\)

假设一个钟表有 \(H\) 小时,一小时有 \(M\) 分钟,求一天中有多少整数分钟,满足时针、分钟夹角不超过 \(\frac {2\pi A}{HM}\)

思路

  1. 时针角速度:\(v_h=\frac {2\pi}{HM}\),分针角速度: \(v_m=\frac {2\pi}{M}\)

  2. 设 \(t\) 分钟时 \((v_m-v_h)*t\equiv \frac {2\pi A}{HM}\pmod {H*M}\)

    即 \((H-1)*t\equiv A \pmod {H*M}\), 求有多少个 \(t\) 满足 \((H-1)*t \mod ({H*M})<=A\)

  3. 在 \(ax\equiv b\pmod m\) 中,令 \(g=\gcd(a,m)\)

    则 \(x\in[0,m-1]\),在模 m 意义下 \(a*x\) 有 \(g\) 轮循环,每轮有 \(0,a,2*a...\) 等 \(\lfloor\frac mg\rfloor+1\) 种取值

  4. 因此模为 \([1,A]\) 有 \(\frac Ag\) 种取值

  5. 对称地,模为 \([H*M-A,H*M-1]\) 与 \([1,A]\) 的 \(x\) 取值的对应,也有 \(\lfloor\frac Ag\rfloor\) 个, 再假设 模为 0 恒有一个

  6. 有 \(g\) 轮循环,答案为 \(ans=(\lfloor\frac Ag\rfloor*2+1)*g\)

  7. 注意特判,当 \(A == \frac {HM}2\) 时,所有分钟都是,即有 \(H*M\) 个,但按上述算法,由于 \(A==H*M-A\) ,会多算一个

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll H, M, A;
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
} ll solve()
{
if (A * 2 == H * M)
return H * M;
ll a = H - 1, m = H * M;
ll g = gcd(m, a);
ll ans = (A / g * 2 + 1) * g;
return ans;
} int main()
{
cin >> H >> M >> A;
cout << solve() << endl;
return 0;
}

2020ICPC沈阳I - Rise of Shadows的更多相关文章

  1. 2020 ICPC 沈阳站 I - Rise of Shadows 题解

    题面看这里 \(PS\):符号 \([\ \rm P\ ]\) 的意义是:当表达式 \(\rm P\) 为真则取值为 \(1\),为假则取值为 \(0\). 题目大意 给你一个一天有 \(H\)​​​ ...

  2. 2020ICPC沈阳站C题 Mean Streets of Gadgetzan

    大致题意 原题链接 翻译 \(有n个逻辑变量 请你分别对它们赋值 使其满足m个命题\) \(命题有四种格式:\) 单独数字x 表示第x个逻辑变量为真 ! + 数字x 表示第x个逻辑变量为假 若干个数字 ...

  3. Material Design系列第四篇——Defining Shadows and Clipping Views

    Defining Shadows and Clipping Views This lesson teaches you to Assign Elevation to Your Views Custom ...

  4. The Rise of Meta Learning

    The Rise of Meta Learning 2019-10-18 06:48:37 This blog is from: https://towardsdatascience.com/the- ...

  5. 2016ACM/ICPC亚洲区沈阳站-重现赛赛题

    今天做的沈阳站重现赛,自己还是太水,只做出两道签到题,另外两道看懂题意了,但是也没能做出来. 1. Thickest Burger Time Limit: 2000/1000 MS (Java/Oth ...

  6. hdu 1004 Let the Balloon Rise

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  7. Let the Balloon Rise 分类: HDU 2015-06-19 19:11 7人阅读 评论(0) 收藏

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  8. HDU 1004 Let the Balloon Rise map

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  9. HDU1004 Let the Balloon Rise(map的简单用法)

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  10. HD1004Let the Balloon Rise

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

随机推荐

  1. 使用stream流对数据进行处理

    1. 使用场景 本次使用是通过条件查询出所需要的多个字段后,对其进行处理(一个条件查询多个下拉框内容,并对每个下拉框内容封装对象,进行返回) 2. 代码 点击查看代码 //获取所有需要的数据 List ...

  2. React子组件继承父组件的props

    https://zh-hans.reactjs.org/warnings/unknown-prop.html

  3. kafka集群under replicated分析

    近期随着业务消息量增大,现网几套kafka集群频繁收到under repliacted告警,集合近期定位分析过程,主要有以下几个方面:1. 查看是否有主机挂掉,或近期是否有主机重启,通过kafdrop ...

  4. nginx通过参数代理到其他站点

    http { include mime.types; default_type application/octet-stream; resolver 8.8.8.8; ##Nginx0.6.18以后的 ...

  5. TCAM and CAM memory usage inside networking devices(转)

    TCAM and CAM memory usage inside networking devices Valter Popeskic Equipment and tools, Physical la ...

  6. IE和FireFox 对FORM enctype属性的认识存在差异

    IE和FireFox 对FORM enctype属性的认识存在差异,一般来说对于动态创建的form,如果因为要上传文件的原因很自然的会使用类似如下的代码: 1  //create form 2  th ...

  7. 直播软件源码,uniapp滚动条置顶实现

    直播软件源码,uniapp滚动条置顶实现 实现功能: uniapp置顶滚动条.自定义页面滚动条的位置 实现代码: uni.pageScrollTo({    scrollTop: 0,    dura ...

  8. lib_0001_file_manager.py

    #!/usr/bin/python # -*- coding: UTF-8 -*- import os import pathlib import shutil import sys class fi ...

  9. pj_0001_compare_col_csv

    #!/usr/bin/python# -*- coding: UTF-8 -*- import pathlibimport pandas as pd print("please input ...

  10. Modern C++ ——constexpr的各种用法

    Modern C++ --constexpr的用法 Reference <现代C++语言核心特性解析> 为什么引入constexpr const可以定义常量,但也可以用来定义只读变量.co ...