Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

好吧,我认了,谁来看一下。。。

Posted by acm_test at 2009-05-28 15:50:58 on Problem 2354
//pku2354 Titanic

#include "iostream"
#include "cmath"
#include "algorithm"
using namespace std;

#define Pi acos(-1.0) 

//计算球面两点圆心角
double angle(double lng1,double lat1,double lng2,double lat2)
{
	double dlng=fabs(lng1-lng2);
	while(dlng>=360)
		dlng-=360;
	if(dlng>180)
		dlng=360-dlng;
	dlng=dlng*Pi/180.0;
	lat1=lat1*Pi/180,lat2=lat2*Pi/180;
	return acos(cos(lat1)*cos(lat2)*cos(dlng)+sin(lat1)*sin(lat2));
}

int main()
{
	//freopen("in.txt", "r", stdin);
	char line[400];
	//while(fgets(line, 400, stdin)!=0)
	while(scanf("%s", line) && line[0]=='M')
	{
		if(line[0]!='M') continue;
		int d, f, m;
		char ch[100];
		//fgets(line, 400, stdin);
		//fgets(line, 400, stdin);
		//fgets(line, 400, stdin);
		//sscanf(line, "%d^%d'%d\" %c", &d, &f, &m, &ch[0]);
		gets(line);
		gets(line);
		gets(line);
		scanf("%d^%d'%d\" %s", &d, &f, &m, ch);
		double bnl=d*3600.0+f*60.0+m;
		if(ch[0]=='S')
			bnl=-bnl;
		//fgets(line, 400, stdin);
		//sscanf(line, "%s%d^%d'%d\" %c", ch, &d, &f, &m, &ch[0]);
		gets(line);
		scanf("and %d^%d'%d\" %s", &d, &f, &m, ch);
		double bwl=d*3600.0+f*60.0+m;
		if(ch[0]=='W')
			bwl=-bwl;
		//fgets(line, 400, stdin);
		//fgets(line, 400, stdin);
		//sscanf(line, "%d^%d'%d\" %c", &d, &f, &m, &ch[0]);
		gets(line);
		gets(line);
		scanf("%d^%d'%d\" %s", &d, &f, &m, ch);
		double inl=d*3600.0+f*60.0+m;
		if(ch[0]=='S')
			inl=-inl;
		//fgets(line, 400, stdin);
		//sscanf(line, "%s%d^%d'%d\" %c", ch, &d, &f, &m, &ch[0]);
		gets(line);
		scanf("and %d^%d'%d\" %s", &d, &f, &m, ch);
		double iwl=d*3600.0+f*60.0+m;
		if(ch[0]=='W')
			iwl=-iwl;
	
		double dis=6875.0/2.0*angle(bwl/3600.0, bnl/3600.0, iwl/3600.0, inl/3600.0);
		dis=floor(dis*100)*0.01;
		printf("The distance to the iceberg: %.2lf miles.\n", dis);
				 
		if(dis<100.0)
			printf("DANGER!\n");
	}

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator