# uva11529 - Strange Tax Calculation 凹四边形个数

1 篇文章 0 订阅

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
评论
• 0
收藏
• 打赏
• 扫一扫，分享海报

08-22 929
08-19 1145
11-05 1万+
12-27 2685
10-22 3893
07-09 2102
07-18 2213
02-26 7089
02-25 1891
07-18 1万+
06-08 1761
04-27 6112
06-30 8万+
©️2022 CSDN 皮肤主题：大白 设计师：CSDN官方博客

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。