首页 > 代码库 > UVA - 11529 Strange Tax Calculation
UVA - 11529 Strange Tax Calculation
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
|
Problemsetter:Shahriar Manzoor
SpecialThanks: Derek Kisman
题意:求有n个点,任意三个点可以组成三角形,计算平均每个三角形包含几个点
思路:应用到了极角排序,详见:HDU 3629
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> typedef long long ll; using namespace std; const int maxn = 2410; const double pi = acos(-1.0); const double eps = 1e-9; struct point { double x, y; } p[maxn]; double du[maxn]; ll cal(int n,int cnt) { ll cur = n, tmp = cnt; for (int i = 1; i < cnt; i++) { cur *= n - i; tmp *= i; } return cur / tmp; } double solve(int n) { double ans = 0; double s = (double) cal(n-1, 3); double c = (double) cal(n, 3); int cur; for (int i = 0; i < n; i++) { cur = 0; for (int j = 0; j < n; j++) if (i != j) { du[cur] = atan2(p[j].y - p[i].y, p[j].x - p[i].x); if (du[cur] < eps) du[cur] += 2 * pi; cur++; } sort(du, du+n-1); for (int j = cur; j < 2*cur; j++) du[j] = du[j-cur] + 2 * pi; double tmp = 0; int pos = 1; for (int j = 0; j < cur; j++) { while (pos <= 2*cur && du[pos]-du[j] < pi) pos++; if (pos - j > 2) tmp += cal(pos-j-1, 2); } ans += (s - tmp) / c; } return ans; } int main() { int n, cas = 1; while (scanf("%d", &n) != EOF && n) { for (int i = 0; i < n; i++) scanf("%lf%lf", &p[i].x, &p[i].y); printf("City %d: %.2lf\n", cas++, solve(n)); } return 0; }