1058 - Grand Prix

You are the chief designer of a road race that will be held in a hilly area. The racecourse consists of Nconnected straight line segments; that is, the end of the k th segment coincides with the beginning of the(k + 1) st segment. During planning, these segments are laid out on a planar surface, so 2-dimensional Cartesian coordinates identify the endpoints. The first segment begins at the origin. Figure 1 shows the planar view of a racecourse with 6 segments.

\epsfbox{p2377a.eps}

The actual race is run on the side of a hill. For simplicity, assume the hill makes an angle $ \theta$ with the horizontal plane, as illustrated in Figure 2.

The plane of the hill and the horizontal plane intersect in the y -axis. Each 2-dimensional Cartesian coordinate (xiyi) corresponds to a 3-dimensional form (xi'yi'zi') , with zi' representing the height of the endpoint of the i th linear segment. The height of the origin is 0.

This particular race is intended for novice drivers, so the racecourse must not include any segments that require downhill travel. That is, if the height of the endpoint of segment k is zk' , then the height of the endpoint of each segment after segment k must not be less than zk' . Formally we can write zk'$ \le$zm' , for m$ \ge$k .

If a proposed racecourse includes downhill segments, it might be possible to transform it into a racecourse with no downhill segments by rotating the planar view of the entire course about the origin, without changing the angle between consecutive pairs of segments. However there may be proposed racecourses that cannot be made acceptable by such a rotation.

In this problem you must determine if a proposed racecourse is acceptable (that is, if it does not contain any downhill segments). If it is not acceptable, you must determine the minimum angle through which the racecourse must be rotated to make it acceptable, if that is possible.

\epsfbox{p2377b.eps}

Input 

The input consists of multiple test cases. Each test case is a description of a proposed racecourse and the slope of the hillside on which it will be run. The first line of each description contains two integers N (1$ \le$N$ \le$10000) and $ \theta$(0o$ \le$$ \theta$$ \le$45o) . N denotes the number of segments in the course and $ \theta$ denotes the angle (in degrees) that the hillside makes with the horizontal plane. Each of the next N lines contains a pair of integers (xiyi) , (1$ \le$i$ \le$N) , which are the endpoints of the linear segments comprising the racecourse. The first segment begins at the origin, and segment k + 1 begins at the endpoint of segment k . No segment has zero length.

The last test case is followed by a line containing two zeroes.

Output 

For each test case, print a line containing the test case number (beginning with 1). If the proposed course is acceptable without rotation, print ``Acceptable as proposed". If the course is not acceptable as proposed, but can be made acceptable by rotating it about the origin, print ``Acceptable after clockwise rotation of Xdegrees" or ``Acceptable after counterclockwise rotation of X degrees". The value X should be an unsigned number. For our purposes, a clockwise rotation would rotate the positive y -axis toward the positive x -axis. If both a clockwise and a counterclockwise rotation can make the course acceptable, choose the one with the smaller angle. If both rotations have the same angle, then choose the clockwise rotation. If the course cannot be made acceptable by any rotation, print ``Unacceptable". Display the angles of rotation rounded to two fractional digits.

Print a blank line after the output for each test case. Use an output format similar to that shown in the sample output below.

Sample Input 

2 45 
10 10 
0 1 
2 0 
1 1 
2 0 
3 45 
10 10 
1 10 
5 6 
0 0

Sample Output 

Case 1: Acceptable after clockwise rotation of 131.99 degrees 

Case 2: Acceptable as proposed

Case 3: Unacceptable



#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
const double pi=acos(-1.0);
double ans1,ans2,X,tmp;
int cases,n,i,j,th,x,y;
int point[11000][2];
double angle[31000];
int main()
{
	cases=0;
	while(1)
	{
		scanf("%d %d",&n,&th);
		if(n==0 && th==0)
			break;
		point[0][0]=point[0][1]=0;
		for(i=1;i<=n;i++)
			scanf("%d %d",&point[i][0],&point[i][1]);
		if(th==0)
		{
			printf("Case %d: Acceptable as proposed\n\n",++cases);
			continue;
		}
		for(i=0;i<n;i++)
		{
			x=point[i+1][0]-point[i][0];
			y=point[i+1][1]-point[i][1];
			if(x>0)
				angle[i]=acos(double(y/sqrt(double(x*x+y*y))));
			if(x<0)
				angle[i]=2*pi-acos(double(y/sqrt(double(x*x+y*y))));
			if(x==0&&y>0)
				angle[i]=0;
			if(x==0&&y<0)
				angle[i]=pi;
		}
		sort(angle,angle+n);
		if(angle[n-1]<=pi)
		{
			printf("Case %d: Acceptable as proposed\n\n",++cases);
			continue;
		}
		ans1=ans2=-1;
		for(i=0;i<n;i++)
		{
			X=pi*2-angle[i];
			tmp=angle[(i+n-1)%n]+X;
			if(0<=tmp&&tmp<=pi)
			{
				if(ans1<0||X<ans1)
					ans1=X;
			}

			X=angle[i]-pi;
			if(X<0)
				X+=pi*2;
			tmp=angle[(i+1)%n]-X;
			if(0<=tmp&&tmp<=pi)
			{
				if(ans2<0||X<ans2)
					ans2=X;
			}
		}
		printf("Case %d: ",++cases);

		if(ans1<0&&ans2<0)
			printf("Unacceptable\n\n");
		else
			if(ans1>=0&&(ans2<0||ans1<ans2+1e-6))
				printf("Acceptable after clockwise rotation of %.2lf degrees\n\n",ans1/pi*180);
			else
				printf("Acceptable after counterclockwise rotation of %.2lf degrees\n\n",ans2/pi*180);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值