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

求凸包之后n*n过了 RC就运行错误QWQ

Posted by Thecats at 2017-03-02 16:50:56 on Problem 2187 and last updated at 2017-03-02 16:51:09
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<sstream>
#include<queue>
#define eps 1e-8
using namespace std;

int n,tp1,tp2;
vector <int> Q;
double ans=0;

struct point{
	double x,y;
}tp3,tp4,P[50012];

double Xmult(point c,point a,point b)
{
	return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}

double DT(point E,point F)
{
	//cout<<E.x<<" "<<E.y<<" "<<F.x<<" "<<F.y<<" "<<endl;
	return (E.x-F.x)*(E.x-F.x)+(E.y-F.y)*(E.y-F.y);
}

bool cmp(point a,point b)
{
	return  (Xmult(P[0],a,b)>eps||(Xmult(P[0],a,b)>-eps&&a.y<b.y)||(Xmult(P[0],a,b)>-eps&&a.y<=b.y&&a.x<=b.x));
}

int main()
{
	tp3.x=10086;
	tp3.y=10086;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf%lf",&P[i].x,&P[i].y);
		if(tp3.y>P[i].y||(tp3.x>P[i].x&&tp3.y>=P[i].y)){
			tp3=P[i];
			tp1=i;
		}
	}
	P[tp1]=P[0];
	P[0]=tp3;
	sort(P+1,P+n,cmp);
	tp1=0;
	for(int i=0;i<n;i++){
		if(tp1<=2){
			Q.push_back(i);
			tp1++;
			continue; 
		}
		while(tp1>=3&&Xmult(P[Q[tp1-2]],P[Q[tp1-1]],P[i])<0){
			Q.pop_back();
			tp1--;
		}
		Q.push_back(i);
		tp1++; 
	}
	//cout<<"----------------"<<endl;
	//for(int i=0;i<tp1;i++){
	//	cout<<P[Q[i]].x<<" "<<P[Q[i]].y<<endl;
	//}
	//cout<<endl<<endl;
	tp3.y=-10086;
/*	for(int i=0;i<tp1;i++){
		if(P[Q[i]].y>tp3.y){
			tp3.y=P[Q[i]].y;
			tp2=i;
		}
	}
	
*/	//RC
	tp2=1;
	Q.push_back(Q[0]);
	tp1++;
	for(int i=0;i<tp1;i++){
		while(Xmult(P[Q[i]],P[Q[i+1]],P[Q[tp2]])<Xmult(P[Q[i]],P[Q[i+1]],P[Q[tp2+1]])){
			tp2=(tp2+1)%tp1;
		}
	//	cout<<tp2<<" "<<i<<endl;
	//	cout<<P[Q[tp2]].x<<" "<<P[Q[tp2]].y<<" + "<<P[Q[i]].x<<" "<<P[Q[i]].y<<" "<<endl;
	//	cout<<DT(P[Q[i]],P[Q[tp2]])<<endl;
	//	cout<<endl;
		
		ans=max(ans,max(DT(P[Q[i]],P[Q[tp2]]),DT(P[Q[i+1]],P[Q[tp2+1]])));
	//	cout<<
	}
	printf("%.0lf\n",ans);
	
	/*(n*n)
	for(int i=0;i<tp1;i++){
		for(int j=0;j<tp1;j++){
			ans=max(ans,DT(P[Q[i]],P[Q[j]]));
		}
	}
	printf("%.0lf",ans);*/
	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