poj2632



package work;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class A2632 {
 static int T, A, B, N, M;
 static int[] X;
 static int[] Y;
 static int[] stad;
 static char direc;
 static int robnum, moved, time;

 public static void main(String[] args) throws FileNotFoundException {
  /* Scanner sc=new Scanner(System.in); */
  Scanner sc = new Scanner(new File("src/2632.txt"));
  T = sc.nextInt();
  for (int t = 0; t < T; t++) {
   A = sc.nextInt();
   B = sc.nextInt();
   N = sc.nextInt();
   M = sc.nextInt();
   X = new int[N];
   Y = new int[N];
   stad = new int[N];
   for (int i = 0; i < N; i++) {
    X[i] = sc.nextInt();
    Y[i] = sc.nextInt();
    direc = sc.next().charAt(0);
    if (direc == 'E')
     stad[i] = 0;
    else if (direc == 'S')
     stad[i] = 1;
    else if (direc == 'W')
     stad[i] = 2;
    else if (direc == 'N')
     stad[i] = 3;
   }
   boolean flag = false;
   for (int i = 0; i < M; i++) {
    robnum = sc.nextInt();
    moved = sc.next().charAt(0);
    time = sc.nextInt();
    if (moved == 'F') {
     if (!flag) {
      for (int j = 0; j < time; j++) {
       if (stad[robnum] == 0)
        X[robnum]++;
       else if (stad[robnum] == 1)
        Y[robnum]--;
       else if (stad[robnum] == 2)
        X[robnum]--;
       else if (stad[robnum] == 3)
        Y[robnum]++;
       flag = jude(robnum);
       if (flag)
        break;
      }
     } else if (moved == 'L')
      stad[robnum] = (stad[robnum] - time % 4 + 4) % 4;
     else if (moved == 'R')
      stad[robnum] = (stad[robnum] + time % 4) % 4;
    }
    if (!flag)
     System.out.println("OK");

   }
  }

 }

 private static boolean jude(int k) {
  if (X[k] <= 0 || X[k] > A || Y[k] <= 0 || Y[k] > B) {
   System.out.println("Robot " + k + " crashes into the wall");
   return true;
  }
  for (int i = 0; i < N; i++) {
   if (i == k)
    continue;
   if (X[k] == X[i] && Y[k] == Y[i]) {
    System.out.println("Robot " + k + " crashes into robot " + "i");
    return true;
   }
  }

  return false;
 }
}

//

4
5 4
2 2
1 1 E
5 4 W
1 F 7
2 F 7
5 4
2 4
1 1 E
5 4 W
1 F 3
2 F 1
1 L 1
1 F 3
5 4
2 2
1 1 E
5 4 W
1 L 96
1 F 2
5 4
2 3
1 1 E
5 4 W
1 F 4
1 L 1
1 F 20

//

Robot 1 crashes into the wall
OK


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值