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;
}

UVA - 11529 Strange Tax Calculation

时间: 2024-10-07 01:19:45

UVA - 11529 Strange Tax Calculation的相关文章

uva 11529 - Strange Tax Calculation(计数问题)

题目链接:uva 11529 - Strange Tax Calculation 题目大意:给出若干个点,保证随意三点不共线.随意选三个点作为三角行,其它点若又在该三角形内,则算是该三角形内部的点.问全部情况的三角形平均每一个三角形有多少个内部点. 解题思路:三角形的总数非常easy求C(3n),如今就是要求各个三角形内部点的总数.相同我们能够反过来,求每一个点在多少个三角形的内部. 然后我们确定一个点,求该点在多少个三角的内部.剩余n-1个点.能够组成C(3n?1])个三角形,所以仅仅要求出该

UVA 11529 - Strange Tax Calculation(计数问题)

题目链接:11529 - Strange Tax Calculation 题意:平面上n个建筑物,3个建筑物可以组成一个三角形,计算平均每个三角形内有多少个点 思路:问题等价于,求凹四边形的占所有四边形的比例,用O(n^2)的算法,跟 HDU 3629 Convex 这题是一个道理 代码: #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> using n

《算法竞赛入门经典——训练指南》第二章题库

UVa特别题库 UVa网站专门为本书设立的分类题库配合,方便读者提交: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=442 注意,下面注有"extra"的习题并没有在书中出现,但在上面的特别题库中有,属于附加习题. 基础练习 (Basic Problems) UVa11388 GCD LCM UVa11889 Benefit UVa10943 How do y

UVA 12123 - Magnetic Train Tracks(计数问题)

题目链接:12123 - Magnetic Train Tracks 题意:给定n个点,求有几个锐角三角形. 思路:和UVA 11529是同类的题,枚举一个做原点,然后剩下点根据这个原点进行极角排序,然后利用two pointer去遍历一遍,找出角度小于90度的锐角,然后扣掉这些得到钝角三角形的个数,然后在用总情况去扣掉钝角就是锐角或直角 代码: #include <stdio.h> #include <string.h> #include <math.h> #incl

解决Tax discount configure 报出异常

If your tax calculation is based on a problematic configuration, the following warnings appear: Warning. Tax discount configuration might result in different discounts than a customer might expect for store(s); Europe Website (French), Europe Website

CN00 与CN28 区别

做过SAP HR的大都知道,SAP在中国区提供的Payroll schema有两个,一个是CN00,一个是CN28.两者最大的区别是,一个是把计税的结果带到当月,另外一个是把税基带到当月. 我现在碰到了一个客户,它的需求是,如果上月员工有发薪水(存在Payroll result),那么就把税基带到本月,如果上月员工薪水就没有发,那么就把税的结果带到本月: 于是我便仔细研究这两个schema的差别的出结果如下 首先来看看SAP标准的schema处理两种算税模式时候的差别: 1.         C

UVa 12342 Tax Calculator (水题,纳税)

今天在uva看到一个水题,分享一下. 题意:制定纳税的总额,有几个要求,如果第一个180000,不纳,下一个300000,纳10%,再一个400000,纳15%,再一个300000,纳20%,以后的纳25%,如果总额大于0但是不过2000,纳2000, 如果总金额不是整数,纳离它最近的且比它大的整数. 析:没什么可说的,算一下就行,也没坑. 代码如下: #include <bits/stdc++.h> using namespace std; const int s[] = {1180000,

UVa 10519 - !! Really Strange !!

题目:一个举行内有n和圆,他们分别互相相交于不同的两个点,问他们把平面分成几部分. 分析:大整数,递推.F(n)= F(n-1)+ 2(n-1). 如果已经有n-1个圆,加入第n个,分别与前n-1个圆相交生成2(n-1)个交点,把圆分割成2(n-1)段弧: 每段弧会把他所属的区域一分为二,F(n)= n(n-1)+ 2 { 其中,n ≥ 1 }. 说明:注意输入为0特殊处理. #include <algorithm> #include <iostream> #include <

UVA 14000 Lighting System Design(DP)

You are given the task to design a lighting system for a huge conference hall. After doing a lot of calculation & sketching, you have figured out the requirements for an energy-efficient design that can properly illuminate the entire hall. According