数学专项counting:LA 4064
来源:互联网 发布:linux查看mysql的表 编辑:程序博客网 时间:2024/05/05 03:39
即求平面上n个点共能构成多少个锐角三角形和直角三角形。我的方法是先统计钝角的总数,然后用C(n,3)减去即可。钝角统计的方法:枚举原点,将剩下的点级角排序,然后二根扫描线扫,即可统计钝角个数。这里需要注意精度问题。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int maxn=2500;const double eps=1e-8;const double pi=acos(-1.0);struct point{double x,y;};int dcmp(double x){ if(fabs(x)<eps) return 0; else return x<0?-1:1;}point p[maxn];double a[maxn];int main(){ //freopen("in.txt","r",stdin); int n,kase=1; while(~scanf("%d",&n) && n) { for(int i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y); long long ans=0; for(int i=0;i<n;i++) { if(i!=0) swap(p[0],p[i]); for(int j=1;j<n;j++) a[j]=atan2(p[j].y-p[0].y,p[j].x-p[0].x); sort(a+1,a+n); for(int j=1;j<n;j++) a[n+j-1]=a[j]+2*pi; int p=1,q=1; for(int j=1;j<n;j++) { while(dcmp(a[p]-a[j]-pi/2)<0) p++; while(dcmp(a[q]-a[j]-pi)<0) q++; ans+=q-p; } } ans=(long long)n*(n-1)*(n-2)/6-ans; printf("Scenario %d:\n",kase++); printf("There are %lld sites for making valid tracks\n",ans); } return 0;}
- 数学专项counting:LA 4064
- 数学专项counting:LA 5846
- 数学专项counting:LA 3357
- 数学专项counting:LA 3720
- 数学专项counting:LA 3295
- 数学专项number_theory:LA 4079
- 数学专项number_theory:LA 2955
- 数学专项matrix:LA 2561
- 数学专项number_theory:LA 3262
- 数学专项number_theory:LA 3521
- 数学专项number_theory:LA 4382
- 数学专项counting:UVa 11038
- 数学专项counting:UVa 10883
- 数学专项counting:UVa 10079
- 数学专项counting:UVa 10081
- 数学专项counting:UVa 580
- 数学专项counting:UVa 417
- 数学专项counting:UVa 11529
- MySQL排序检索数据----ORDER BY
- python设置默认字符编码
- putty连接Ubuntu(安装ssh并开启服务)
- 责任分散效应
- 陕西省第一届ACM程序设计竞赛D题(最大生成树)
- 数学专项counting:LA 4064
- ubuntu下安装code::blocks
- linux网络接口配置文件
- 帕金森定律
- dns污染
- Live555 直播
- linux 双链表实现
- java内置常用的分析命令
- TinyXML:一个优秀的C++ XML解析器