uva11529 - Strange Tax Calculation 凹四边形个数

来源:互联网 发布:手机淘宝一元秒杀在哪 编辑:程序博客网 时间:2024/04/30 01:21

The people living in large citieshave to pay more tax than people living in rural areas. That is because incities people have many facilities, which rural people don’t have. Also peoplein large and famous cities tend to pay more tax than people living in smallercities or towns. Government of Euphoria now has a strange rule to decide taxrate – Tax rate of a house is proportional to the total number of houses within1 kilometer radius of it. The rule apparently seems ok, but as a result peoplehave started building houses 500 meters away from the main city and in this waythey are enjoying all the facilities but paying much less taxes. Also in thisway the town has begun to expand very quickly, which is not desirable.

 

So the government of Euphoria nowdecides to make a new tax rule which will be less (or not) understood by commonpeople and hence it will have less chance of being manipulated. In the newrule, tax depends on the number of high rise buildings in the city and theirorientation. Any three high rise building makes Bermuda block in the city andthe tax depends on average number of high rise buildings per Bermudablock.

 


Figure 1: High-rise buildings of Euphoria

Figure 2: The black circles denote the locations of high-rise buildings. Of the 10 Bermuda blocks only 2 contains one high-rise building each. So the average number of high-rise building per Bermuda block is 2/10 = 0.2. This figure corresponds to the first sample input.

 

As total number of buildings canbe high so you have to help the Mayor of Euphoria to write an efficient programthat will help calculate tax.

 

Input

The input file contains severalsets of inputs.

 

Each set starts with an integer N(0 ≤ N ≤ 1200), which denotes the total number of high risebuilding in the city. Each of the next N lines contains two integers xi, yi (0 ≤ xi,yi≤ 10000)which actually denotes that the Cartesian coordinate of the i-th high-risebuilding is (xi, yi). You can assume that the cityis located on a flat land and it is so large that a point can actually be usedto denote the position of a high-rise building. You can also assume that nothree buildings are on the same straight line and no two buildings are at thesame place either.

 

Input is terminated by a case where N=0.

 

Output

For each setof input produce one line of output. This line contains the serial of outputfollowed by a floating-point number. This floating-point number denotes theaverage number of high rise buildings per Bermudablock.  This floating-point number shouldbe rounded to two digits after the floating-point. Look at the output forsample input for details.

 

Sample Input                            Output for SampleInput

5

29 84

81 81

28 36

60 40

85 38

5

0 0

10 0

0 10

10 10

6 7

0

City 1: 0.20

City 2: 0.20

 

  求平均一个三角形内有几个点。

  相当于反过来求一个点在几个三角形内,也相当于求凹四边形的个数。最后再除以C(N,3)。

  每次枚举一个点作为中点,把其他点按照和中点的极角排序,按极角从小到大算出每个点和它逆时针的2个点能组成的使中点在三角形之外(中点在逆时针侧)的三角形的个数,判断方法就是找到第一个和点i极角大小和j极角大小之差大于等于180度的,从i+1到j-1的点任选2个都可以和i点组成中点外的三角形。

 j只需要循环一次,注意j有可能超过一圈,因此要把数组延长一倍,并且r[i+k]=r[k]+2*pi。复杂度是N^2。


  例如i为1的情况



#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<cstdlib>#include<cmath>#define INF 0x3f3f3f3f#define MAXN 1210#define MAXM 20010#define MAXNODE 4*MAXN#define MOD 1000000000#define eps 1e-9#define pi 4*atan(1.0)using namespace std;int N;double r[2*MAXN];struct Point{    double x,y;}p[MAXN];double C(int n,int m){    double ret=1;    for(int i=0;i<m;i++) ret=ret*(n-i)/(i+1);    return ret;}double cal(int num){    int k=0;    double ret=0;    for(int i=0;i<N;i++) if(i!=num) r[k++]=atan2(p[i].y-p[num].y,p[i].x-p[num].x);    sort(r,r+k);    for(int i=0;i<k;i++) r[k+i]=r[i]+2*pi;    int j=1;    for(int i=0;i<k;i++){        while(fabs(r[j]-r[i])<pi) j++;  //j只需要循环一次        ret+=C(j-i-1,2);    }    return C(k,3)-ret;}int main(){    //freopen("in.txt", "r", stdin);    int cas=0;    while(scanf("%d",&N),N){        for(int i=0;i<N;i++) scanf("%lf%lf",&p[i].x,&p[i].y);        double sum=0;        for(int i=0;i<N;i++) sum+=cal(i);        printf("City %d: %.2lf\n",++cas,sum/C(N,3));    }    return 0;}


0 0