HBC17850Rikka with Ants题解 (每日一词:ants)

2拍不死你 算法基础篇 49 0
全网最全C++题库,助您快速提升编程技能!题库丰富多样,涵盖各个领域,让您在练习中不断成长!
There are two small ants on Rikka's desk. If we consider Rikka's desk as a two-dimensional Cartesian coordinate system, both of them have coordinate (1,0). Now, Rikka places three obstacles on her desk: 1. y = 0, none of the two ants can walk cross this line. 2.y=abxy = frac{a}{b}xy=bax, only the second ant can walk cross this line. 3.y=cdxy = frac{c}{d}xy=dcx, only the first ant can walk cross this line. It's remarkable that it is allowed for the ants to stand exactly on the obstacles. For example, if a=b=c=d=1, then both of the ants can reach (1,0),(1,1),(2,1),(2,2) and none of them can reach (1,2),(2,3). Now, the ants start to move. Their strategy is very simple: In each second, let (x,y) be the current coordinate of one ant, if it can reach , it will walk to this point, otherwise it will walk to .. The following image shows the first ant's path when a=3,b=2: Now, given a,b,c,d, let p1 be the first ant's path and p2 be the second ant's path. Rikka wants you to calculate the number of the points with integer coordinates which are on both p1 and p2.

There are two small ants on Rikka's desk. If we consider Rikka's desk as a two-dimensional Cartesian coordinate system, both of them have coordinate (1,0). Now, Rikka places three obstacles on her desk: 1. y = 0, none of the two ants can walk cross this line. 2. y=abx(a,b>0)y = frac{a}{b}x(a,b > 0)y=ba​x(a,b>0), only the second ant can walk cross this line. 3.  y=cdx(c,d>0)y = frac{c}{d}x(c,d > 0)y=dc​x(c,d>0), only the first ant can walk cross this line. It's remarkable that it is allowed for the ants to stand exactly on the obstacles. For example, if a=b=c=d=1, then both of the ants can reach (1,0),(1,1),(2,1),(2,2) and none of them can reach (1,2),(2,3). Now, the ants start to move. Their strategy is very simple: In each second, let (x,y) be the current coordinate of one ant, if it can reach (x,y+1), it will walk to this point, otherwise it will walk to (x+1,y).(Since ab,cd>0frac{a}{b},frac{c}{d} >0ba​,dc​>0, if the ant can reach (x,y), it can also reach (x+1,y)). The following image shows the first ant's path when a=3,b=2: Now, given a,b,c,d, let p1 be the first ant's path and p2 be the second ant's path. Rikka wants you to calculate the number of the points with integer coordinates which are on both p1 and p2.

HBC17850Rikka with Ants题解
(每日一词:ants)-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断挑战自我,才能突破极限!全网最全C++题库,让您在编程道路上越走越远。

标签: HBC17850Rikka with Ants题解