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

Re:发现超级大水题

Posted by yygy at 2023-05-15 20:16:27 on Problem 2354
In Reply To:发现超级大水题 Posted by:yygy at 2023-05-15 15:24:01
// MyFirstApp.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>

using namespace std;

typedef __int64 lld;

const int MAXN = 512;

//经度角a, 纬度角b
double GeodesicDistance(double r, double a1, double b1, double a2, double b2)
{
	return r * acos(cos(b1) * cos(b2) * cos(a1 - a2) + sin(b1) * sin(b2));
}

int GetNum(char *s, int& iter, int len)
{
	//找到第一个数字位
	while (iter < len && !isdigit(s[iter]))
	{
		iter++;
	}

	if (iter < len)
	{
		int d = 0;
		//是数字位一直前进
		while (iter < len && isdigit(s[iter]))
		{
			d = d * 10 + s[iter] - '0';
			iter++;
		}

		return d;
	}
	else
	{
		return -1;
	}
}

void GetLatitude(char* s, double& lat1)
{
	lat1 = 0;
	//41^46'00" NL
	int len = strlen(s);
	int iter = 0;
	int down = 1;
	int d = -1;
	while ((d = GetNum(s, iter, len))>=0)
	{
		printf("d=%d\n", d);
		lat1 += d * 1.0 / down;
		down *= 60;
	}

	const double pi = acos(-1.0);

	lat1 = lat1 / 180 * pi;

	int id = 0;
	for (id = len - 1; id >= 0; id--)
	{
		if (s[id] == 'L')
		{
			break;
		}
	}
	if (s[id-1] == 'S')
	{
		lat1 = -lat1;
	}
}

void GetLongitude(char* s, double& lon1)
{
	lon1 = 0;
	//50^14'00" WL.
	int len = strlen(s);
	int iter = 0;
	int down = 1;
	int d = -1;
	while ((d = GetNum(s, iter, len)) >= 0)
	{
		printf("d=%d\n", d);
		lon1 += d * 1.0 / down;
		down *= 60;
	}

	const double pi = acos(-1.0);

	lon1 = lon1 / 180 * pi;

	int id = 0;
	for (id = len - 1; id >= 0; id--)
	{
		if (s[id] == 'L')
		{
			break;
		}
	}

	if (s[id - 1] == 'W')
	{
		lon1 = -lon1;
	}
}

bool ReadData(double& lat1, double& lon1, double& lat2, double& lon2)
{
	char s[10][100];
	for (int i = 0; i < 9; i++)
	{
		if (!cin.getline(s[i], 1024))
		{
			return false;
		}
	}

	//3 
	GetLatitude(s[3], lat1);
	//4 
	GetLongitude(s[4], lon1);
	//6 
	GetLatitude(s[6], lat2);
	//7
	GetLongitude(s[7], lon2);

	return true;
}

int main()
{
	double a1, b1, a2, b2;
	while (ReadData(b1, a1, b2, a2))
	{
		double ans = GeodesicDistance(6875.0, a1, b1, a2, b2);
		printf("The distance to the iceberg : %.2f miles.\n", ans);

		double diff = ans * 100 - 10000;
		if (fabs(diff) > 1e-6 && diff < 0)
		{
			puts("DANGER!");
		}

	}

	return 0;
}

/*
Sample Input

Message #513.
Received at 22:30:11.
Current ship's coordinates are
41^46'00" NL
and 50^14'00" WL.
An iceberg was noticed at
41^14'11" NL
and 51^09'00" WL.
===
Sample Output

The distance to the iceberg: 52.04 miles.
DANGER!

6875
*/

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