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> ...
随机推荐
- Java进阶知识26 SSH整合(Struts2、Spring、Hibernate)
1.我用到的jar包 2.整合实例 2.1.数据库建表语句 create database school; -- 创建数据库 use school; -- 使用school数据库 create tab ...
- [Luogu] 让我们异或吧
https://www.luogu.org/problemnew/show/P2420 异或满足 A ^ B = B ^ A A ^ A = 0 0 ^ A = A #include <cstd ...
- Codeforces 1180E Serge and Dining Room
题意: 有\(n\)个菜肴,有\(m\)个小朋友,每个菜肴的价格为\(a_i\),每个小朋友有\(b_i\)元钱,小朋友从\(1 \rightarrow m\)依次购买菜肴,当第\(i\)个小朋友轮到 ...
- SQL SERVER可重复执行建表、建字段语句
/*问题:type in (N'U') 中的N和U是什么意思? 答案:N是指Unicode编码,防止乱码:U是指用户表*/IF NOT EXISTS (SELECT * FROM sys.object ...
- tesseract 安装及使用
安装软件 tesseract下载地址:https://digi.bib.uni-mannheim.de/tesseract/ 安装即可! 安装完成tesseract-ocr后,需要做一下配置 . 在P ...
- bash基础之三配置文件
一.shell的两种登录方式: 1.交互式登录:(1)直接通过终端输入账号密码登录(2)使用“su - UserName” 或“su -l Username”切换的用户执行顺序:/etc/profil ...
- <cmath>库函数
C++ cmath库中的函数 今天模拟,想调用<cmath>中的函数,然鹅...突然忘了,所以还是总结一下吧 写法 作用 int abs(int i) 返回整型参数i的绝对值 double ...
- POJ2689
题目 POJ2689 Prime Distance 原题传送门 主要思路 刚看到这题,心想:不就筛个 \(\left[2,U\right]\) 的质数表出来就可以了吗?一看数据范围: \(1<= ...
- 分享一个seata demo,讲两个个问题
Seata,阿里开源的分布式事务框架,多的我就不介绍了,了解详细介绍,请看官网.seata spring boot入门,可以看我上一篇博客<Spring boot微服务如何集成fescar解决分 ...
- chrome console控制台引入jquery库
var jqueryJs=document.createElement('script');jqueryJs.setAttribute("type","text/Java ...