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 hahaxiao at 2005-09-06 19:36:22 on Problem 2504
#define pi 3.1415926535897932
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
	double a,b;
	double x,y;
	double x1,y1,x2,y2,x3,y3;
	double xmax,xmin,ymax,ymin;
	double angle,ang;
	double k1,k2;
	int n,t,i=0;
	while(1) {
		cin>>n;
		if(n==0) break;
		if(n==1 || n==2 ){
			cout<<0.000<<endl;
			continue;
		}
		cin>>x1>>y1>>x2>>y2>>x3>>y3;
		if(x1==x2) {//如果((x1,y1),(x2,y2))垂直于x轴
			if(y2==y2) {x=(x2+x3)/2.0;   y=(y1+y2)/2.0; }  //如果((x2,y2),(x3,y3))平行于x轴
			else {x=(y3-y2)*(y3-y1)/(2.0*(x3-x2));   y=(y1+y2)/2.0; }
		}
		else if(y1==y2) {//如果((x1,y1),(x2,y2))平行于x轴
			if(x2==x3) {x=(x1+x2)/2.0;   y=(y2+y3)/2.0; }//如果((x2,y2),(x3,y3))垂直于x轴
			else {x=(x1+x2)/2.0;   y=(x3-x2)*(x3-x2)/(2.0*(y3-y2))+(y2+y3)/2.0;}
		}
		else {
			if(y2==y3) {x=(x2+x3)/2.0;  y=(x2-x1)*(x1-x3)/(2.0*(y2-y1))+(y1+y2)/2.0;}
			else if(x2==x3) {
				x=(y2-y1)*(y1-y3)/(2.0*(x2-x1))+(x1+x2)/2.0;
				y=(y2+y3)/2.0;
			}
			else {
				k1=(y2-y1)/(x2-x1); k2=(y3-y2)/(x3-x2);
				x=(k2*(x1+x2))/(2.0*(k2-k1))-(k1*(x2+x3))/(2.0*(k2-k1))+(k1*k2*(y1-y3))/(2.0*(k2-k1));
				y=-(x2-x1)*(x-(x1+x2)/2.0)/(y2-y1)+(y1+y2)/2.0;
				
			}
		}
		//以上是找出多边形的中心
		a=x1-x; b=y1-y; //求出向量(a,b)
		ang=2.0*pi/(1.0*n);
		xmax=a;xmin=a;ymax=b;ymin=b;
		for(t=1;t<n;t++) { //逆时针旋转找出x的最大,最小值,找出y的最大,最小值
			angle=ang*t;
			x=a*cos(angle)-b*sin(angle);
			y=a*sin(angle)+b*cos(angle);
			if(x>xmax) xmax=x;
			if(x<xmin) xmin=x;
			if(y>ymax) ymax=y;
			if(y<ymin) ymin=y;
		}
		++i;
		cout<<"Polygon "<<i<<": ";
		cout<<setprecision(3)<<setiosflags(ios::fixed)<<(ymax-ymin)*(xmax-xmin)<<resetiosflags(ios::fixed)<<endl;
	}
	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