枚举一个中心点,然后将其他点绕着这个点按照极角排序。

统计这个中心点在外面的三角形的个数,然后用C(n-1, 3)减去这个数就是包含这个点的三角形的数量。

然后再枚举一个起点L,终点为弧度小于π的点R。

在[L+1, R]任取两点再加上起点,这些三角形都不包含中心点。

 #include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std; const int maxn = + ;
const double PI = acos(-1.0); struct Point
{
int x, y;
}p[maxn];
double ang[maxn * ];
typedef Point Vector; double inline C2(int n) { return n * (n-) / ; }
double inline C3(int n) { return n * (n-) / * (n-) / ; }
double solve(int n)
{
double s = C3(n-), ans = ;
for(int i = ; i < n; i++)
{//枚举中心点
int k = ;
for(int j = ; j < n; j++) if(j != i)
{
ang[k] = atan2(p[j].x-p[i].x, p[j].y-p[i].y);
ang[k + n - ] = ang[k] + 2.0 * PI;
k++;
}
k = *(n-);
sort(ang, ang + k);
int L = , R = ;
double t = ;
for(L = ; L < n-; L++)
{
double temp = ang[L] + PI;
while(temp > ang[R]) R++;
t += C2(R - L - );
}
ans += s - t;
}
return ans;
} int main()
{
//freopen("in.txt", "r", stdin); int n, kase = ;
while(scanf("%d", &n) == && n)
{
for(int i = ; i < n; i++)
scanf("%d%d", &p[i].x, &p[i].y);
double ans = solve(n) / C3(n);
printf("City %d: %.2f\n", ++kase, ans);
} return ;
}

代码君

UVa 11529 (计数) Strange Tax Calculation的更多相关文章

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

    题目链接:uva 11529 - Strange Tax Calculation 题目大意:给出若干个点,保证随意三点不共线.随意选三个点作为三角行,其它点若又在该三角形内,则算是该三角形内部的点.问 ...

  2. uva 11529 Strange Tax Calculation (几何+计数)

    题目链接: http://vjudge.net/problem/viewProblem.action?id=18277 这题暴力n^4妥妥的TLE!即使n^3也可能会T 正确的姿势应该是:枚举每个点作 ...

  3. UVa 1640 (计数) The Counting Problem

    题意: 统计[a, b]或[b, a]中0~9这些数字各出现多少次. 分析: 这道题可以和UVa 11361比较来看. 同样是利用这样一个“模板”,进行区间的分块,加速运算. 因为这里没有前导0,所以 ...

  4. UVA 10564 计数DP

    也是经典的计数DP题,想练练手,故意不写记忆化搜索,改成递推,还是成功了嘞...不过很遗憾一开始WA了,原来是因为判断结束条件写个 n或s为0,应该要一起为0的,搞的我以为自己递推写挫了,又改了一下, ...

  5. UVa 11481 (计数) Arrange the Numbers

    居然没有往错排公式那去想,真是太弱了. 先在前m个数中挑出k个位置不变的数,有C(m, k)种方案,然后枚举后面n-m个位置不变的数的个数i,剩下的n-k-i个数就是错排了. 所以这里要递推一个组合数 ...

  6. UVa 11609 (计数 公式推导) Teams

    n个人里选k个人有C(n, k)中方法,再从里面选一人当队长,有k中方法. 所以答案就是 第一步的变形只要按照组合数公式展开把n提出来即可. #include <cstdio> typed ...

  7. UVa 11361 (计数 递推) Investigating Div-Sum Property

    题意: 统计[a, b]中有多少个数字满足:自身是k的倍数,而且各个数字之和也是k的倍数. 分析: 详细分析见<训练之南>吧,=_=|| 书上提出了一个模板的概念,有了模板我们就可以分块计 ...

  8. UVA 10519 !! Really Strange !!

    //ans=2*n+(n-1)(n-2) n>=2#include <map> #include <set> #include <list> #include ...

  9. UVa 11529

    题目大意:见刘汝佳<算法竞赛入门经典——训练指南>P173 解题思路: 先求出对于每一个点,有多少个三角形包含它,把各个点得到的数值加起来的总和除以 C[n][3] 即可得出答案.对于每一 ...

随机推荐

  1. 历时一周,unity3d+xtion打造我的第一个休闲体感小游戏《空降奇兵》

    1.游戏介绍 本游戏属于休闲小游戏,主要操作如下: 菜单控制:举起左手或右手,点击左边或者右边的菜单:挥动左手或右手,选择关卡: 操作方式:玩家跳跃,游戏中的伞兵从飞机开始降落:玩家通过控制伞兵的左右 ...

  2. SOLID architecture principles using simple C# examples

    转:http://www.codeproject.com/Articles/703634/SOLID-architecture-principles-using-simple-Csharp?msg=4 ...

  3. MyEclipse 2015 Stable 1.0下载安装破解日志

    前言 这2天下载了许多myeclipse版本,基本上是14/15版本的,各种破解均告以失败,这次下载了贴吧一个吧友提供的版本,现已破解.破解结果现不好说--目前已装SVN,根据经验,只有等待一定时间验 ...

  4. 【HDOJ】【1693】Eat The Trees

    插头DP 插头dp模板题…… 这题比CDQ论文上的例题还要简单……因为不用区分左右插头(这题可以多回路,并不是一条哈密尔顿路) 硬枚举当前位置的状态就好了>_< 题解:http://blo ...

  5. [转载]Windows 7 IIS (HTTP Error 500.21 - Internal Server Error)解决

    今天在测试网站的时候,在浏览器中输入http://localhost/时,发生如下错误: HTTP Error 500.21 - Internal Server Error Handler " ...

  6. iOS开发之数据存取3-CoreData自定义数据类型

    当系统提供的类型不能达到我们的使用要求时,比如我想在CoreData中存储UIColor,该怎么办呢? 这时候就要用到CoreData中非常强大的一个存储类型了:Transformable 下面将通过 ...

  7. [设计模式] 21 策略模式 Strategy

    在GOF的<设计模式:可复用面向对象软件的基础>一书中对策略模式是这样说的:定义一系列的算法,把它们一个个封装起来,并且使它们可相互替换.该模式使得算法可独立于使用它的客户而变化. 策略模 ...

  8. Understanding and Using Servlet Filters

    Overview of How Filters Work This section provides an overview of the following topics: How the Serv ...

  9. Namespace, string, vector and array

    1. Headers should not include using declaration Code inside headers ordinarily should not include us ...

  10. JsRender系列demo-对null 和boolen类型数据的探讨

    废话不说了,直接上代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <he ...