#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 100000
using namespace std;
int numcolor = 0,numpoint = 0;
long long int d[2*N],bot,top;
int temp;
char a[100][1000];
typedef struct POINT{
long long int x,y,index;
}POINT;
POINT point[100][N];
POINT point2[100][N];
long long int ccw(POINT p1,POINT p2,POINT p3){
long long ans;
ans = (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x);
return ans;
}
int cmp(const void *a,const void *b){
POINT *c = (POINT*) a;
POINT *d = (POINT*) b;
if(c->x!=d->x)
return c->x-d->x;
else
return c->y-d->y;
}
long long int cal(POINT a,POINT b,POINT c){
return (a.x*(c.y-b.y)+b.x*(a.y-c.y)+c.x*(b.y-a.y));
}
long long int area(int a){
long long sum = 0;
for(int i=0;i<a-2;i++)
sum = sum + cal(point[0][0],point[0][i+1],point[0][i+2]);
if(sum<0)
sum = 0-sum;
return sum;
}
void convex_hull_single(int npoints, int col){
int i, t, k = 0;
/* lower hull */
for (i = 0; i < npoints; ++i) {
while (k >= 2 && ccw(point2[col][k-2], point2[col][k-1], point[col][i]) <= 0) --k;
point2[col][k++] = point[col][i];
}
/* upper hull */
for (i = npoints-2, t = k+1; i >= 0; --i) {
while (k >= t && ccw(point2[col][k-2], point2[col][k-1], point[col][i]) <= 0) --k;
point2[col][k++] = point[col][i];
}
if(k==1)
k++;
else{
for(int i3 = 0;i3<k;i3++){
point2[col][i3].x = point2[col][i3+1].x;
point2[col][i3].y = point2[col][i3+1].y;
}
}
point2[col][0].index = k-2;
}
void convex_hull_double(int npoints, int col){
int i, t, k = 0;
/* lower hull */
for (i = 0; i < npoints; ++i) {
while (k >= 2 && ccw(point[0][k-2], point[0][k-1], point2[0][i]) <= 0) --k;
point[0][k++] = point2[0][i];
}
/* upper hull */
for (i = npoints-2, t = k+1; i >= 0; --i) {
while (k >= t && ccw(point[0][k-2], point[0][k-1], point2[0][i]) <= 0) --k;
point[0][k++] = point2[0][i];
}
//if(k==1)
//k++;
//else{
//for(int i3 = 0;i3<k;i3++){
//point2[0][i3].x = point2[0][i3+1].x;
//point2[0][i3].y = point2[0][i3+1].y;
//}
//}
point2[0][0].index = k-2;
}
long long int read(){
char b[20];
int flag = 1,X,Y;
while(cin>>X!=NULL){
cin>>Y;
gets(b);
int k =0;
for(int i = 1;i<=numcolor;i++){
flag = strcmp(b,a[i]);
if (flag==0){
k = i;
point[k][0].index++;
point[k][point[k][0].index].x=X;
point[k][point[k][0].index].y=Y;
goto next;
}
}
strcpy(a[numcolor+1],b);
point[numcolor+1][0].x=X;
point[numcolor+1][0].y=Y;
point[numcolor+1][0].index= 0;
numcolor++;
next:
;
numpoint++;
}
return numcolor;
}
int main(){
long long int i,total,j,i1,length;
long long int max=0,max1,max2;
total=read();
//printf("%lld\n",total);
//puts(a[0]);
//puts(a[1]);
//puts(a[2]);
//puts(a[3]);
//cout<<point[1][0].x<<point[1][0].y<<endl;
//cout<<point[1][1].x<<point[1][1].y<<endl;
//cout<<point[2][0].x<<point[2][0].y<<endl;
//cout<<point[3][0].x<<point[3][0].y<<endl;
//cout<<point[1][0].index<<point[1][0].index<<endl;
//cout<<point[5][0].x<<point[5][0].y<<point[5][1].x<<point[5][1].y<<endl;
if (total==0){
return 0;
}
if (total==1){
puts(a[1]);
return 0;
}
//for(int i2 = 1;i2<7;i2++)
//cout<<" "<<point[i2][0].index<<" "<<endl;
//cout<<point[6][0].x<<point[6][0].y<<point[6][1].x<<point[6][1].y<<endl;
for(int i2 = 1;i2<=numcolor;i2++){
temp = point[i2][0].index;
qsort(point[i2],temp+1,sizeof(point[i2][0]),cmp);
point[i2][0].index =temp;
convex_hull_single(point[i2][0].index+1,i2);
}
//for(int i2 = 1;i2<7;i2++)
//cout<<" "<<point2[i2][0].index<<" "<<endl;
for (i=1;i<total;i++){
for (j=i+1;j<=total;j++){
length=point2[i][0].index+point2[j][0].index+2;
for (i1=0;i1<=point2[i][0].index;i1++)
point2[0][i1]=point2[i][i1];
for (i1=point2[i][0].index+1;i1<length;i1++)
point2[0][i1]=point2[j][i1-1-point2[i][0].index];
qsort(point2[0],length,sizeof(point[0][0]),cmp);
point2[0][0].index = length-1;
// cout<<"length shi "<<length<<endl;
//for(int i2 = 0;i2<length;i2++)
//cout<<"11!!"<<point2[0][i2].x<<" "<<point2[0][i2].y<<endl;
convex_hull_double(length,0);
//for(int i2 = 0;i2<length;i2++)
//cout<<"22!!"<<point2[0][i2].x<<" "<<point2[0][i2].y<<endl;
//sort(length); tubao
//melkman(length);
//cout<<area(length)<<endl;
if (area(point2[0][0].index+2)>max){
max=area(point2[0][0].index+2);
max1=i;
max2=j;
}
}
}
i=0;
//cout<<max<<endl;
//cout<<max1<<" "<<max2<<endl;
if (strcmp(a[max1],a[max2])>0){
max1=max1+max2;
max2=max1-max2;
max1=max1-max2;
}
if(max%2 ==0)
printf("%lld",max/2);
if(max%2==1)
printf("%lld.5",max/2);
while(a[max1][i]!='\0'){
printf("%c",a[max1][i++]);
}
puts(a[max2]);
return 0;
}
color convex_hull
最新推荐文章于 2025-05-30 16:07:57 发布
