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

统计这个中心点在外面的三角形的个数,然后用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. Makedown常用符号整理

    整理自:http://www.jianshu.com/p/1e402922ee32 不过这里发现博客园的makedown语法支持还不完善,代码语法显示挺有问题的,比较遗憾. 标题 # 一级标题## 二 ...

  2. ubuntu 安装git

    问题描述:         ubuntu安装git 问题解决:     (1)ubuntu下载git 注:           使用命令apt-get install git安装     (2)查看g ...

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

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

  4. uva 10205 模拟

    模拟题 题目描述挺长的.... #include <cstdio> #include <cstdlib> #include <cmath> #include < ...

  5. 国内最大的 Node.js 社区将 New Relic 的监控产品换成了 OneAPM

    国内最知名的 CNode 社区把 New Relic 的监控产品换成了 OneAPM .难道 APM 的老大 New Relic 已经被 OneAPM 超越? 毋庸置疑,在全球应用性能管理 SaaS ...

  6. linq中查询列表的使用及iqueryable和list集合之间的转换

    linq中查询列表的使用及iqueryable和list集合之间的转换 比如要查询一个货架集合,但是只需要其id和name即可,可以用以下方法:先写一个model类:CatalogModel(注意该类 ...

  7. C# foreach循环绑定key数组和value 数组(备用)

    <div class="ContextualTab inner_warp clearfix" data-max="2" data-blur=false d ...

  8. mac 设置 ll 等alias 并永久生效

    往上看了在.bash_profile中配置 然后 source  的方法, 试过了, 只是当前的终端有效,当电脑重启或者关闭终端就失效了,只好看看 mac 的 profile 代码 # System- ...

  9. MAC OS JAVA环境变量配置

    在  /etc/profile 中 加上这些 #临时提权 sudo su #输入密码 vi /etc/profile #配置JAVA_HOME,此处路径根据自己的版本填写 JAVA_HOME=&quo ...

  10. Project Euler 78:Coin partitions

    Coin partitions Let p(n) represent the number of different ways in which n coins can be separated in ...