Ultraviolet-11529 strange tax calculation

Source: Internet
Author: User

 

The people living in large citieshave to pay more tax than people living in rural areas. that is because incities people have ready 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 be 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

28 36

60 40

85 38

5

0 0

10 0

0 10

10 10

6 7

0

City 1: 0.20

City 1: 0.20

 

 

Problemsetter: Shahriar Manzoor

Specialthanks: Derek kisman

Question: There are N points. Any three points can form a triangle. The calculation average shows that each triangle contains several points.

Idea: applied to polar sorting. For details, refer to 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;}


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.