View Code of Problem 12

#include<stdio.h>
/*导弹与发射塔的距离distance= c/1000000*t/2*/ 
int main()
{
	int n;
	int i=0 ;
	int count=0;
	scanf("%d",&n);
	while(n--)
	{i++;
		int flag;
		double sc=200000;
		double f1,f0;
		int t;
		double c=299792458;
		scanf("%d%lf%lf%d",&flag,&f0,&f1,&t);
		double distance=c/1000000*t/2;
		double v=c*(f1-f0)/(f1+f0);
		if(flag==1)
		{
			printf("Target%d:NO:ONE OF US\n",i);//若为己方,输出 NO:ONE OF US
		}
		else
		{
			if(v<0)//若方向取反,输出NO:AWAY
			{
				printf("Target%d:NO:AWAY\n",i);		
			}
			else if(distance<sc)//在射程范围内 
			{
				if(count<3)//拦截的目标是三个以内输出YES
				{
					printf("Target%d:YES\n",i);
					count++;//每次拦截一个拦截目标加一 
				}
				else 
				{
					printf("Target%d:NO:NEXT TIME\n",i);//拦截的目标超过三个输出NO:NEXT TIME 
				}
			}
			else 
			{
				printf("Target%d:NO:%.4lf\n",i,(distance-sc)/v);//在拦截范围外,计算进出拦截区的时间 
			}	
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 12