View Code of Problem 12

import java.util.Scanner;
 
 
 
public class Main {
	public static void main(String[] args)  {
		Scanner scanner = new Scanner(System.in);
		int t  = scanner.nextInt();
		int c = 299792458;
		double dis = Math.pow(10, 5) * 2;
		int count = 3;
		
		for(int i=0; i<t; i++) {
			int index = scanner.nextInt();
			double f0 = scanner.nextDouble();
			double f1 = scanner.nextDouble();
			int time = scanner.nextInt();
			
			if(index==1) {
				System.out.println("Target"+ (i+1)+":NO:ONE OF US");
			}else {
				double v = c*(f1-f0) / (f0+f1);
				double d = (time * 1e-6) *c/2;
				if(v < 0) {
					System.out.println("Target"+(i+1)+":NO:AWAY");
				}else {
					if(d < dis) {
						if(count >0) {
							System.out.println("Target"+ (i+1)+":YES");
							count --;
						}else {
							System.out.println("Target"+ (i+1) + ":NO:NEXT TIME");
						}
					}else {
						double ti = (d -dis)/v;
						System.out.println("Target"+ (i+1)+":NO:"+String.format("%.04f", ti));
					}
				}
			}
		}
	}
 
 
}

Double click to view unformatted code.


Back to problem 12