hzu3-Catch the thief!

http://acm.timus.ru/problem.aspx?space=1&num=1191

1191. Catch the thief!

Time limit: 1.0 second

Memory limit: 64 MB

A thief is fleeinga place of crime. A cop follows him, with a time lag ofLminutes.They run equally fast, thus the lag between them remains constant. Finally,feeling tired, the thief reaches a tram stop. He wants to take a tram of aspecific route; trams follow each other with an interval of exactlyK1minuteson this route at any time of day and night. When the tram comes, the thiefboards it. The policeman comes to the same tram stop. If the thief is stillthere waiting for the tram to arrive, the policeman arrests him. If the thiefis gone, the cop himself waits for a tram of the same route. The thief leaveshis tram at some stop and starts waiting for a tram of another route (trams ofthat route keep an interval of exactlyK2minutes).When a tram arrives, the thief gets on it and continues his way. Of course, thecop leaves his tram also at this stop and, if the thief is still there, arrestshim. If the thief managed to leave, the policeman waits for a tram of the sameroute that the thief used and follows the thief…

This processcontinues until either the policeman arrests the thief or the thief, havingusedNtrams, reaches his secret cover place where he is safe.

Although thespeeds of the cop and the thief remain equal all the time and the speeds oftheir trams are equal, it may happen that the policeman is lucky to overtakethe thief. For instance, ifL<K1,then it may happen that the policeman reaches the first stop when the thief isstill waiting for a tram there. Other situations are also possible. Write aprogram that determines whether the cop can catch the thief.

Input

The input consistsof two lines: in the first line there are the numbersL(0<L< 100) andN(0 <N<100) delimited with a space. In the second line there are time intervalsK1,K2,…,KN(0 <Ki< 100)between trams of the corresponding routes. These numbers are also separatedwith spaces. All numbers in the input data are integers.

Output

Output NO if thecop has no chance to overtake the thief before he reaches his cover place;output YES if he still has such a chance.

Samples

input

output

8 3

6 4 3NO

15 4

7 3 13 6YES

中文释义:

警察和强盗

一个盗贼离开了银行抢劫的现场。

一个警察在L分钟后开始追赶他。他们跑得一样快。也就是说,这之间的时间延迟是不变的。

最后,因为感到一点疲劳,盗贼来到了一个电车站。他想搭乘一辆电车,这条路线电车的发车间隔都是确定的K1分钟,

当电车到达的时候,盗贼上了车。

那个警察也在盗贼到达车站后L分钟后到达了这个车站。如果这时盗贼还在等车,那么警察就把他捉走了。

或者,警察开始等那一条路线的车。在一些站,盗贼下了车,开始等待另外一条路线的车(发车时间是固定的K2分钟),

当车来到的时候,盗贼就继续搭车。当然,警察与盗贼一样,也在那个站下车,捉住盗贼,

或者盗贼已经上了另外一辆车——好吧,那警察就再等待盗贼后来上的电车,跟着盗贼……

这个过程会不断持续直到警察捉住了盗贼或盗贼搭乘了N辆电车,到了使他安全的秘密地点。

虽然警察和盗贼的速度相同,各个电车速度也相同,但是仍然会有警察赶上盗贼的情况。

如果L

当然其他的情况也有可能出现。写一个程序判断盗贼能否逃过正义的制裁。

输入:

输入文件包括两行,第一行是L(0

第二行也是用空格分开,包括盗贼搭乘的电车的发车时间(按照相应的顺序)K1,K2,K3……KN(0

输出:

输出应该只含有一个全部是大写字母的单词——NO,如果警察没有机会捉到盗贼,或YES,如果警察还有机会的话。

解题思路:

从整体上看,每到一个间隔为a的车站,两人间距离就会减少dis mod a那么多。

相应代码:

#include

using namespace std;

int main() {

int L,N;

cin >> L >> N;

int a[N];

for (int i = 0;i < N;i++) {

cin >> a[i];

L -= L%a[i];

//cout << L<< endl;

}

if (L<= 0) cout << "YES"<< endl;

else cout <<"NO" << endl;

return 0;

}

你可能感兴趣的:(hzu3-Catch the thief!)