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> ...
随机推荐
- 【luogu1468】[Violet]蒲公英--求区间众数
题目背景 亲爱的哥哥: 你在那个城市里面过得好吗? 我在家里面最近很开心呢.昨天晚上奶奶给我讲了那个叫「绝望」的大坏蛋的故事的说!它把人们的房子和田地搞坏,还有好多小朋友也被它杀掉了.我觉得把那么可怕 ...
- 2Dot grammar
http://www.cnblogs.com/mjios/archive/2013/04/08/3006577.html . #import <Foundation/Foundation.h&g ...
- 数据分析之numpy使用
使用numpy生成数字 生成的类型是ndarray类型 t1 = np.array([1,2,3,4,5]) print(t1,type(t1)) # 类型为ndarray t2 = np.array ...
- HDU 4386 Quadrilateral(四边形的海伦公式的应用)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115760#problem/G 题目大意是给出四条边,问能否组成一个四边形,如果 ...
- 取出easyui的datagrid的总数
var grid = $('#datagrid'); var options = grid.datagrid('getPager').data("pagination").opti ...
- Raspberry Pi 4B 使用OpenCV访问摄像头picamera模块
目录 1.OpenCV安装 (1)安装依赖 (2)下载OpenCV源码 (3)安装pip (4)安装Python虚拟机 (5)编译OpenCV (6)验证安装 2.使用OpenCV和Python控制摄 ...
- DataTable 转换为List
注意table 列的参数类型,若不为string 需要详细声明 如 typeof(Int32) public static IList<T> Convert ...
- 慢查询explan详解
慢查询排查 show status; // 查询mysql数据库的一些运行状态 show status like 'uptime'; // 查看mysql数据库启动多 ...
- DBMS_STATS.GATHER_SCHEME_STATS学习
由于Oracle的优化器是CBO,所以对象的统计数据对执行计划的生成至关重要! 作用:DBMS_STATS.GATHER_TABLE_STATS统计表,列,索引的统计信息(默认参数下是对表进行直方图信 ...
- Qemu搭建ARM vexpress开发环境(一)
Qemu搭建ARM vexpress开发环境(一) 标签(空格分隔): Qemu ARM Linux 嵌入式开发离不开硬件设备比如:开发板.外设等,但是如果只是想学习研究Linux内核,想学习Linu ...