[Moscow2016] [Gym101137B] Blocking Buer(数学)

New microarchitecture for parallel programming has a pipe buer to organize the data exchange between two execution threads. The buer is circular and can contain no more than l bytes. At the beginning of the program execution the buer is empty. The rst thread sometimes tries to write to the buer, and it always uses blocks of size w bytes. The second thread sometimes reads from the buer in blocks of size r bytes each. All write operations put the new data at the end of the pipe buer and all read operations take the data from the beginning of the pipe buer, so empty positions always form one continuous segment. Both write and read operations are blocking. It means that, if the rst thread tries to write the block of data to the buer but there is not enough space there, the thread stops and waits until there will be at least w empty bytes in the buer. Similarly, if the second thread tries to read the block of data from the buer but there are less than r bytes of data left, the thread stops and waits until there will be enough new data in the buer. In this particular problem, a deadlock is a situation when the rst thread is blocked because there is not enough space in the buer to t a new block of size w, and the second thread is blocked because there is not enough data in the buer to read a new block of size r. Your goal is to determine whether there exists such a sequence of reads and writes from two threads that will result in a deadlock. Note that write operations are only performed by the rst thread and read operations are only performed by the second thread.

Input

The only line of input contains three integers l, r and w (0 < l, r, w ≤ 1018 , r ≤ l, w ≤ l).

Output

If there exists a sequence of reads and writes that result in a deadlock, print DEADLOCK (without quotes) in the only line of the output. Otherwise, print OK (without quotes).

 

对r和w取个gcd,除下来,去掉那些不能达到的状态。然后,能发生死锁的条件就是r+w-2>=l(YY一下)。证明不会。

 

#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
    #ifdef ULTMASTER
    freopen("a.in", "r", stdin);
    #endif
    long long l, r, w;
    cin >> l >> r >> w;
    long long gg = gcd(r, w);
    l /= gg; r /= gg; w /= gg;
    if (r + w - 2 >= l)
        cout << "DEADLOCK" << endl;
    else cout << "OK" << endl;
    return 0;
}

  

posted @ 2016-12-08 13:27  ultmaster  阅读(583)  评论(0编辑  收藏  举报