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

  1. if $S > 0$, A and B never meet,
  2. if $S = 0$, they meet infinitely many times,
  3. 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的更多相关文章

  1. [AtCoder] NIKKEI Programming Contest 2019 (暂缺F)

    [AtCoder] NIKKEI Programming Contest 2019   本来看见这一场的排名的画风比较正常就来补一下题,但是完全没有发现后两题的AC人数远少于我补的上一份AtCoder ...

  2. AtCoder AISing Programming Contest 2019 Task D. Nearest Card Game

    题目分析在代码注释里. int main() { #if defined LOCAL && !defined DUIPAI ifstream in("main.in" ...

  3. [AtCoder] Yahoo Programming Contest 2019

    [AtCoder] Yahoo Programming Contest 2019   很遗憾错过了一场 AtCoder .听说这场是涨分场呢,于是特意来补一下题. A - Anti-Adjacency ...

  4. 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 ...

  5. AtCoder NIKKEI Programming Contest 2019 C. Different Strokes (贪心)

    题目链接:https://nikkei2019-qual.contest.atcoder.jp/tasks/nikkei2019_qual_C 题意:给出 n 种食物,Takahashi 吃下获得 a ...

  6. 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 ...

  7. 2020.3.14--训练联盟周赛 Preliminaries for Benelux Algorithm Programming Contest 2019

    1.A题 题意:给定第一行的值表示m列的最大值,第m行的值表示n行的最大值,问是否会行列冲突 思路:挺简单的,不过我在一开始理解题意上用了些时间,按我的理解是输入两组数组,找出每组最大数,若相等则输出 ...

  8. Yahoo Programming Contest 2019 自闭记

    A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...

  9. NIKKEI Programming Contest 2019 翻车记

    A:签到. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> ...

随机推荐

  1. rxjs与vue

    原创文章,转载请注明出处 使用vue-rx插件将vue和rxjs联系起来 在main.js中将vue-rx注入vue中 import Vue from 'vue' import App from '. ...

  2. 线程的分离状态 detached joinable

    转自  http://blog.chinaunix.net/uid-26983585-id-3315953.html 其实在写上一篇日志的时候,由于我把创建线程的返回值的判断条件写错了,程序每次运行的 ...

  3. GoEasy实现websocket 推送消息通知到客户端

    最近在实现一个推送功能,用户扫描二维码签到,后台及时将签到成功信息推送到浏览器端.排除了前端ajax轮询的方式,决定采用websocket及时推送. 于是发现了第三方websocket推送库GoEas ...

  4. CF1200A

    CF1200A 解法: 给出长度为n的字符串,字符串由'L'.'R'以及数字0~9组成.旅馆有10间房子,L代表客人从左边入住,R代表客人从右边入住,数字则表示第i间房子客人退房了.问经过这n次操作后 ...

  5. 安装APK时报错:Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]

    安装APK时报错:Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI] 可以使用adb install -t 解决 对于已经在手机的文件可以使用pm ...

  6. centos7的网络配置参考

    <鸟哥的Linux私房菜>中的相关介绍和配置:http://linux.vbird.org/linux_basic/0610hardware.php 修改链接(connection)的名字 ...

  7. 第11组 Beta冲刺(2/5)

    第11组 Beta冲刺(2/5)   队名 不知道叫什么团队 组长博客 https://www.cnblogs.com/xxylac/p/11997386.html 作业博客 https://edu. ...

  8. git 优雅的撤销中间某次提交

    环境git : 2+ 前言最近两天,公司的git合并代码时,出现了严重的问题,浪费很多时间: 现在记录下: 情况是这样的,一个同事自己的本地分支(远程没有),不知怎么的,有了别人开发分支的代码,而他自 ...

  9. poj1734

    Sightseeing trip Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9078   Accepted: 3380 ...

  10. Flask-SQLAlchemy操作

    Flask-SQLAlchemy   SQLAlchemy 一. 介绍 SQLAlchemy是一个基于Python实现的ORM框架.该框架建立在 DB API之上,使用关系对象映射进行数据库操作,简言 ...