View Code of Problem 12

#include<iostream>
#include <cmath>
using namespace std;
#pragma warning(disable:4996)



int main(){
	int n;
	scanf("%d", &n);
	int count = 1;
	for (int i = 1; i <= n; i++) {
		int tar;
		double f0;
		double f1;
		int t;
		int c = 299792458;
		double dis, area;
		area = 200;
		scanf("%d %lf %lf %d", &tar, &f0, &f1, &t);
		if (tar == 1)
			printf("Target%d:NO:ONE OF US\n",i);
		else {
			dis = (double)c * (t*1e-9) / 2;
			double v;
			v = (f1 / f0 * c - c) / (1 + f1 / f0);
			if (v <= 0) {
				printf("Target%d:NO:AWAY\n",i);
			}		
			else {
				if (dis < area) {
					if (count <= 3) {
						printf("Target%d:YES\n", i);
						count++;
					}
					else {
						printf("Target%d:NO:NEXT TIME\n", i);
					}
				}
				else {
					double ti;
					ti = (dis - area) / v * 1000;
					printf("Target%d:NO:%.4lf\n", i, ti);
				}
			}
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 12