分R==W、R<W、R>W三种情况
import java.util.*; public class Main { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); int L = sc.nextInt(), R = sc.nextInt(), W = sc.nextInt(); if(R > L || W > L){ //读写超过内存总量的,直接死锁 System.out.println("DEADLOCK"); return; } if(R == W) System.out.println("OK"); //读写等大的,交替即可OK if(R < W){ int sum = 0; while(L - sum >= W) sum += W - R; //写大于读的,交替增量直到不能再写 if(sum < R) System.out.println("DEADLOCK"); //增量总量不够读一次,死锁 else System.out.println("OK"); } if(R > W){ int sum = 0; while(sum <= L) sum += W; //读大于写的,先尽量写满 sum -= W; if(sum < R) System.out.println("DEADLOCK"); //不够读一次,死锁 else System.out.println("OK"); } } }