View Code of Problem 12

#include<stdio.h>
#include<algorithm>
#define c 299792458
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int who[100];
	double f0[100],f1[100],t[100];
	double v[100];
	double x[100];
	int a[100]={0};
	int i,j;
	for(i=0;i<n;i++)
	{
	scanf("%d%lf%lf%lf",&who[i],&f0[i],&f1[i],&t[i]);
	f0[i]*=1000000000;f1[i]*=1000000000;
     v[i]=c*(f1[i]-f0[i])/(f1[i]+f0[i]);
	 x[i]=c*t[i]/2/1000000;
	}
	int min=0xfffff;
	int k;
	for(i=0;i<3;i++)
	{
		min=0xfffff;
		for(j=0;j<n;j++)
		{
			if(x[j]<min&&!a[j])
			{
				min=x[j];
				k=j;
			}
		}
		a[k]=1;
	}
	for(i=0;i<n;i++)
	{
		printf("Target%d:",i+1);
		if(who[i]) printf("NO:ONE OF US");
		else if(v[i]<0) printf("NO:AWAY");
		else if(x[i]>200000) printf("%.4f",(x[i]-200000)/v[i]);
		else if(a[i]) printf("YES");
		else printf("NO:NEXT TIME");
		printf("\n");
    }
	return 0;
}

Double click to view unformatted code.


Back to problem 12