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. 洛谷 P3382 【模板】三分法(三分 二分)

    P3382 [模板]三分法 题目提供者HansBug 难度 普及/提高- 题目描述 如题,给出一个N次函数,保证在范围[l,r]内存在一点x,使得[l,x]上单调增,[x,r]上单调减.试求出x的值. ...

  2. Fltiss项目的架构、包名的定义和类的划分

    这是项目的一览 首先Web根目录. 除了WEB-INF以外,还有css,img,js,lib目录,这四者都是静态资源. 由于客户端无法访问WEB-INF下的内容,所以将它们放置在了Web根目录下. 而 ...

  3. shell 字符串分割cut

    cut 选项与参数 -d:后面接分隔字符.与-f一起使用. -f:依据-d的分隔字符将一段信息分隔数段,用-f取出第几段的意思. -c:以字符的单位取出固定字符区间 [zhang@localhost ...

  4. Js 之将字符串当变量使用

    var page1 = 0; var p = "page1"; //修改值 window[p] += 1; var value = eval(p);

  5. 总结:Apache/Tomcat/JBOSS/Jetty/Nginx区别 .

    总结:Apache/Tomcat/JBOSS/Nginx区别 .1.Apache是Web服务器,Tomcat是应用(Java)服务器.Tomcat在中小型系统和并发访问用户不是很多的场合下被普遍使用. ...

  6. Matlab下imwrite,Uint16的深度图像

    Matlab下imwrite,Uint16的深度图像 1. 在Matlab命令窗口输入命令: help imwrite 会有如下解释: If the input array is of class u ...

  7. Linux命令行提交更新冲突

    1.在harry目录下的hello文件第五行加一些内容 2.将修改后文件执行提交操作 提交成功,文件版本升为5 3.在sally目录下同样修改hello文件第五行 4.sally进行提交操作 发现提交 ...

  8. P2308 添加括号

    P2308 添加括号 题解 一看这题---我能AC 看完这题---我要换题 这题第二问其实就是一个链的石子合并,也就是不用处理环 所以一三问怎么处理??? 数组 mid[ i ][ j ] 记录区间 ...

  9. app微信支付的集成步骤

    1.引用地址 //微信支付 compile 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+' 2.注册 private IWXAPI api ...

  10. [go]日志库小例子

    输出日志 //输出日志到console msg := fmt.Sprintf(format, args...) //format里的坑 args解出的数据相匹配 fmt.Fprintf(os.Stdo ...