UVA 11529-strange tax calculation-for triangular points/two points/two pointers

Source: Internet
Author: User

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18277

Plane to n points, guaranteed no three points collinear


If there are x points inside a triangle, contribute x to the contribution of all triangles.

The direct number of points within each triangle is not good, you can reverse the "how many triangles each point contains"



Enumerate each point x, centering the point, and sorting the rest of the points by the polar order,

So for the point J of the Polar Order Y, we find the first point z of the polar order is greater than Y+PI, then from the y+1 to z-1 all points in the choice of two, you can and point y form a "no point x" triangle, so for all points, you can find all the triangle without a point x.


If the angle of two points >pi, does not constitute "the triangle does not contain X", but 2pi-angle is <pi, that is, the other side, so you need to copy the array to twice times

Looking for "The first point z of the polar order is greater than Y+PI," Here I lazy with two points, the total complexity is n (NLGN+NLG)

It is better if it is N (lgn+n) with the pointers.


#include <cstdio> #include <cmath> #include <cstring> #include <string> #include <algorithm&
Gt #include <queue> #include <map> #include <set> #include <vector> #include <iostream> using

namespace Std;
Const double Pi=acos (-1.0); 
Double eps=0.000001; 
int min (int a,int b) {return a<b?a:b;}

int max (int a,int b) {return a>b?a:b;}
	struct node {int x, y;
	Node () {} double Jijiao;
node (int a,int b) {x=a,y=b;}};
Node tm[1255];
Node tmp[2455];
BOOL CMP (node A,node b) {return a.jijiao<b.jijiao;} int n;
	Double count (int x) {int i;
	int idx=1; 
		for (i=1;i<=n;i++) {if (i==x) continue;
		tmp[idx].x=tm[i].x-tm[x].x;
		TMP[IDX].Y=TM[I].Y-TM[X].Y;
		Tmp[idx].jijiao=atan2 (tmp[idx].y,tmp[idx].x);
		Tmp[idx+n-1].jijiao=tmp[idx].jijiao+2*pi;
	idx++;
	} sort (tmp+1,tmp+1+ (2*n-2), CMP);
	node TP;
	Double res=0;
		for (i=1;i<n;i++) {tp.jijiao=tmp[i].jijiao+pi;
		int It=upper_bound (TMP+1,TMP+1+2*N-2,TP,CMP)-tmp; IntCnt=it-i-1;
	res+= cnt* (cnt-1)/2;
	} double s= (n-1) * (n-2) * (n-3)/6.0;
return s-res;
	} int main () {int cnt=1;
	int i;
	while (1) {cin>>n;
	if (!n) break;
	for (i=1;i<=n;i++) {scanf ("%d%d", &tm[i].x,&tm[i].y);
	} double ans=0; 
	for (i=1;i<=n;i++) ans+=count (i);
	
	printf ("City%d:%.2lf\n", cnt++,ans/n/(n-1)/(n-2) *6.0);
	
} return 0; }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.