剩余系

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. HTML网址集合

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. Kubernetes 安装网络插件(calico)

    简介 Calico是Kubernetes生态系统中另一种流行的网络选择.虽然Flannel被公认为是最简单的选择,但Calico以其性能.灵活性而闻名.Calico的功能更为全面,不仅提供主机和pod ...

  3. Unity一键制作预制体Prefab一键修改Prefab属性

    1.适用于制作多个预制体(一个模型文件下面几百个子物体,都需要制作成预制体,这一个一个拖不是要炸裂) 模型资源如下图 2.模型先放到Resources文件夹下面方便读取,制作完预制体可以给他拖到其他文 ...

  4. 关于Python 面向对象寻值的问题. How the number be found in the OOP in Python

    今天在看Python面向对象的时候看到了一个很有意思的问题 Today. When i learning the OOP in python , I found a very interesting ...

  5. 记录一次阿里云ECS搭建代理服务器的过程

    [参考资料](Tinyproxy安装与配置(ip代理) - 林先生 (downdawn.com)) 1.一键安装脚本 vim proxy.sh #! /bin/bash # 配置文件 CONFIG_F ...

  6. ES使用

    shards 分片数 ES存储数据可以存储在多个分片 下载ES curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elas ...

  7. 12组-Beta冲刺-1/5

    12组-Beta冲刺-1/5 一.基本情况 队名:字节不跳动 组长博客:https://www.cnblogs.com/147258369k/p/15590128.html Github链接:http ...

  8. Linux 第四节(shell脚本,IF,do,for)

    Shell脚本 1.批处理式: 2.交互式: 脚本声明   #!/bin/bash 脚本注释   #fakba;kb 脚本命令   ls pwd bash test.sh   //执行test.sh脚 ...

  9. java NIO原理和代码实践

    一,先说java IO 1,线程阻塞:当线程调用write()或read()时,线程会被阻塞,直到有一些数据可用于读取或数据被完全写入. 2,面向流: 我们需要从流中读取一个或多个字节.它使用流来在数 ...

  10. 快速上手springboot(2)

    简介 Spring程序的缺点: 1.依赖设置繁琐 2.配置繁琐 SpringBoot程序优点 1.起步以来(简化依赖配置) 2.自动配置(简化常用工程相关配置) 3.辅助功能(内置服务器,...) S ...