Sumitomo Mitsui Trust Bank Programming Contest 2019 Task F. Interval Running
Link.
There is a nice approach to this problem that involves some physical insight.
In the following we'll refer to Takahashi as A and to Aoki as B.
Without loss of generality, assume $A_1 > B_1$. Consider A's relative motion with respect to B, i.e. imagine B is always at rest. The relative velocity of A is $A_1 - B_1$ for the first $T_1$ minutes and $A_2 - B_2$ for the subsequent $T_2$ minutes.
Let $S = (A_1 - B_1) T_1 + (A_2 - B_2) T_2$, we have
- if $S > 0$, A and B never meet,
- if $S = 0$, they meet infinitely many times,
- if $S < 0$, they meet some finite number of times.
In case $S < 0$, it's not hard to figure out the number of times A and B meet.
code
int main() {
ll t1, t2;
ll a1, a2, b1, b2;
scan(t1, t2, a1, a2, b1, b2);b1 -= a1;
b2 -= a2;
if (b1 < 0) {
b1 = -b1;
b2 = -b2;
}
ll s = b1 * t1 + b2 * t2;
if (s == 0) {
println("infinity");
} else if (s > 0) {
println(0);
} else {
s = -s;
ll k = b1 * t1 / s;
ll ans = 2 * k;
if (b1 * t1 % s == 0) {
++ans;
} else {
ans += 2;
}
println(ans - 1); // -1 because we do not count the start of the run as a meet
}
return 0;
}
Sumitomo Mitsui Trust Bank Programming Contest 2019 Task F. Interval Running的更多相关文章
- [AtCoder] NIKKEI Programming Contest 2019 (暂缺F)
[AtCoder] NIKKEI Programming Contest 2019 本来看见这一场的排名的画风比较正常就来补一下题,但是完全没有发现后两题的AC人数远少于我补的上一份AtCoder ...
- AtCoder AISing Programming Contest 2019 Task D. Nearest Card Game
题目分析在代码注释里. int main() { #if defined LOCAL && !defined DUIPAI ifstream in("main.in" ...
- [AtCoder] Yahoo Programming Contest 2019
[AtCoder] Yahoo Programming Contest 2019 很遗憾错过了一场 AtCoder .听说这场是涨分场呢,于是特意来补一下题. A - Anti-Adjacency ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem F
Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...
- AtCoder NIKKEI Programming Contest 2019 C. Different Strokes (贪心)
题目链接:https://nikkei2019-qual.contest.atcoder.jp/tasks/nikkei2019_qual_C 题意:给出 n 种食物,Takahashi 吃下获得 a ...
- The 2019 China Collegiate Programming Contest Harbin Site F. Fixing Banners
链接: https://codeforces.com/gym/102394/problem/F 题意: Harbin, whose name was originally a Manchu word ...
- 2020.3.14--训练联盟周赛 Preliminaries for Benelux Algorithm Programming Contest 2019
1.A题 题意:给定第一行的值表示m列的最大值,第m行的值表示n行的最大值,问是否会行列冲突 思路:挺简单的,不过我在一开始理解题意上用了些时间,按我的理解是输入两组数组,找出每组最大数,若相等则输出 ...
- Yahoo Programming Contest 2019 自闭记
A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...
- NIKKEI Programming Contest 2019 翻车记
A:签到. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> ...
随机推荐
- devstack cinder-volume服务状态为down
cinder-manage service list 查看到有一个 xxx状态 Binary Host Zone Status State Updated At RPC Version Object ...
- Eclipse生成EXE文件(可视化Login/读取文件)
Java Swing实现文件的简单读取 WindowBuilder的安装与使用 如何采用java设置一个登陆界面 package jp.services.slink2.batch.so2or; imp ...
- Tensorflow使用训练好的模型进行测试,发现计算速度越来越慢
实验时要对多个NN模型进行对比,依次加载直到第8个模型时,发现运行速度明显变慢而且电脑开始卡顿,查看内存占用90+%. 原因:使用过的NN模型还会保存在内存,继续加载一方面使新模型加载特别特别慢,另一 ...
- New in Python 3.8.0
Python 3.8.0 发布时间: Oct. 14, 2019 这是一个Python3.8.0的稳定发行版. Python3.8.0是最新的Python编程语言发行版,ta包含了许多新的特征和优化. ...
- ELK日志解决方案
1.方案整体设计 FileBeats+Logstash+ElasticSearch+Kibana 1)ElasticSearch 简称ES,用来做日志数据的存储,当然也可以存储其他数据, ES是互联网 ...
- 怎样在VMware虚拟机中使用安装并设置Ubuntu系统
1 2 3 4 5 6 7 分步阅读 Ubuntu 系统是一款优秀的.基于GNU/Linux 的平台的桌面系统. 当然,目前为止很多应用程序还完全不能允许运行在 Ubuntu 系统上,而且 Ubunt ...
- Servlet的运行原理
- Dynatrace
1.概述 过去,企业的IT部门在测量系统性能时,一般重点测量为最终用户提供服务的硬件组件的利用率,如CPU利用率以及通过网络传输的字节数.虽然这种方法也提供了一些宝贵的信息,但却忽视了最重要的因素-- ...
- python包中__init__.py文件的作用
python包中__init__.py文件的作用 __init__.py文件最常用的作用是标识一个文件夹是一个 python包. __init__.py文件的另一个作用是定义模糊导入时要导入的内容. ...
- asp.net MVC AngularJS
http://www.cnblogs.com/powertoolsteam/category/834105.html