牛客 2021年度训练联盟热身训练赛第二场 I题Pegasus Circle Shortcut

题目描述

For the UCF High School Programming Tournament, the judges were located in the Engineering building, and most of the teams were in the Classroom building, which is on the other side of Pegasus Circle.

Chris was walking to the Classroom building for the first time, and was joined by Jeremy, who had made the hike a couple of times already.

“Jeremy, is it faster to stay on the circle, or to cut through the middle using the boardwalks that go to the Student Union?” asked Chris.

“I don’t know.” Jeremy answered. “I think it’s about the same, but it might be slightly faster to use the walkways.”

“Well, if it’s about the same, let’s stick to the circle. I don’t want to be attacked by squirrels.”

The Problem:

Given two points on a circle, and two paths to get from one to the other—one following the perimeter of the circle, and the other by a sequence of connected straight line segments through the interior of the circle—determine the shorter of the two paths.

输入描述:

The input will contain multiple test cases, each consisting of two lines. The first line of each testcase contains six floating-point numbers:xc,yc,xs,ys,xf, andyf, where (xc,yc) is the center point of the circle, (xs,ys) is the start point for both paths (e.g., the Engineering building), and (xf,yf) is the finish point for both paths (e.g., the Classroom building).The circle will always have a radius greater than 1, and the start and finish points are both guaranteed to be at distinct pointson its perimeter, with an accuracy of at least 3 placesafter the decimal.The path along the perimeter is always in the directioncounter-clockwise around the circle.

The second line of each test case will start with an integer,n(1≤n≤ 10), followed by n pairs of floating-point numbers,x1,y1,x2,y2, …xn, and yn, where each pair (xi,yi) is a point inside the circle. The interior path traveled will be from point (xs,ys) to point (x1,y1), then from (x1,y1) to (x2,y2), then from (x2,y2) to (x3,y3), …, then from (xn,yn) to (xf,yf).

The last test case will be followed by a line containing six zeros. All numbers on an input line will beseparated from each other by one space, with no extra spaces at the beginning or end of lines. Assumethat all the input floating point numbers will be less than 1000.0 and greater than

-1000.0, with at most 6 places after the decimal.

输出描述:

For each test case in the input, output a line in either the format

Case #n:Stick to the Circle.

if the perimeter path is shorter,or

Case #n:Watch out for squirrels!

if the interior pathis shorter, where n is the num berof the input test case, starting at 1.

Assume that the two paths will not be equal, i.e., it is guaranteed that the two distances will not be equal. In particular, assume that the two paths will differ in length by 0.001 or more.

Leave a blank line after the output for each test case.

输入

5.0 5.0 10.0 5.0 5.0 10.0
6 8.5 4.7 6.9 5.0 3.6 6.5 4.2 7.1 4.2 8.3 4.7 8.8
2.0 8.0 0.5 16.87412 7.5 0.8761
2 3.25 9.25 7.0 7.0
0 0 0 0 0 0

输出

Case #1: Stick to the Circle.

Case #2: Watch out for squirrels!

AC的C++代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
using namespace std;

int main()
{		
	int flag=1;
	double x0;
	while(~scanf("%lf",&x0))
	{
		//第一行
		double y0,x1,y1,x2,y2;
		cin>>y0>>x1>>y1>>x2>>y2;
		if(x0==0 && y0==0 && x1==0 && x2==0 && y1==0 && y2==0)break;
		//求弧长
		double	r = sqrt( (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0) );
		double L1 = r * acos( ((x1-x0)*(x2-x0)+(y1-y0)*(y2-y0)) / (r*r) );
		// 第二行
		int N;
		double L2=0,x,y,a,b,c,d;
		cin>>N;
		a=x1,b=y1;
		for(int i=1; i<=N; i++)
		{
			cin>>c>>d;
			L2 += sqrt( (c-a)*(c-a)+(d-b)*(d-b) );
			a=c,b=d;
		}
		L2 += sqrt( (x2-a)*(x2-a)+(y2-b)*(y2-b) );
		cout << "Case #"<<flag<<": ";
		flag++;
		if(L1 < L2)
			cout<<"Stick to the Circle."<<"\n\n";
		else
			cout<<"Watch out for squirrels!"<<"\n\n";		
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值