CF 333E Summer Earnings
来源:互联网 发布:淘宝店铺出租转让 编辑:程序博客网 时间:2024/06/05 05:59
题意
给点集
题解
先说说正解:
先不考虑三点共线
注意到任何一个三角形都有一个角
注意三点共线的问题,那么这个“三角形”一定有一个角
复杂度
然后,当我知道能bitset水过时,我内心是崩溃的。。。
不妨把
两个启示是:
1. 遇到三角形的时候,可以考虑其内角和一定,利用平均数原理可以得到一个不等式,从而缩减枚举量
2. Bitset在处理三角形时有奇效。。。
code
正常解法:
// 日了狗!竟然有三点共线 #include<algorithm>#include<cstdio>#include<cmath>using namespace std;const double eps=1e-8;const double PI=acos(-1.0);const int maxn=6010;struct Point{ int x,y; Point(){} Point(int x,int y):x(x),y(y){}};Point operator + (const Point &A, const Point &B) { return Point(A.x+B.x, A.y+B.y); }Point operator - (const Point &A, const Point &B) { return Point(A.x-B.x, A.y-B.y); }double Dot(const Point &A, const Point &B) { return (double)A.x*B.x + (double)A.y*B.y; }double Length(const Point &A) { return sqrt(Dot(A, A)); }Point p[maxn];struct Line { Point A, B, v; double ang; Line() { } Line(Point A, Point B): A(A), B(B) { v = B-A; ang = atan2(v.y, v.x); } // ax + by + c > 0 bool operator < (const Line &A) const { return ang < A.ang; }};int n;Line L[maxn];int Q[maxn]; int Ql,Qr;int main(){// freopen("K.in","r",stdin); scanf("%d",&n); for(int i=0;i<n;++i){ int x,y; scanf("%d%d",&x,&y); p[i]=Point(x,y); } double res=0.0; for(int o=0;o<n;++o){ int m=0; for(int i=0;i<n;++i)if(i!=o) { L[m++]=Line(p[o],p[i]); } sort(L,L+m); for(int i=0;i<m;++i) L[i+m]=L[i], L[i+m].ang+=2*PI; Ql=0,Qr=0; int Qp=0; for(int l=0,r=0;l<m;++l){ for(;Qp<2*m&&L[Qp].ang<L[l].ang+PI+eps;){ while(Qr-Ql>=1 && Length(L[Q[Qr-1]].v)<Length(L[Qp].v)) --Qr; Q[Qr++]=Qp++; } for(;r<2*m&&L[r].ang-L[l].ang<PI/3;++r); while(Qr-Ql>=1&&Q[Ql]<r) ++Ql; if (Qr-Ql>=1)res=max(res,min(Length(L[l].v),Length(L[Q[Ql]].v))); }// printf("%.20lf\n",res/2); } printf("%.20lf\n",res/2);// for(;;); return 0;}
bitset:
#include<algorithm>#include<bitset>#include<cstdio>#include<cmath> using namespace std;const int maxn=3010;struct Point{ int x,y; Point(){} Point(int x,int y):x(x),y(y){}};Point operator + (const Point &A, const Point &B) { return Point(A.x+B.x, A.y+B.y); }Point operator - (const Point &A, const Point &B) { return Point(A.x-B.x, A.y-B.y); }double Dot(const Point &A, const Point &B) { return (double)A.x*B.x + (double)A.y*B.y; }double Length(const Point &A) { return sqrt(Dot(A, A)); }Point p[maxn];bitset<maxn> f[maxn];pair<double, pair<int, int> > A[maxn*maxn];int AN;int n;int main(){// freopen("K.in","r",stdin); scanf("%d",&n); for(int i=0;i<n;++i){ int x,y; scanf("%d%d",&x,&y); p[i]=Point(x,y); } AN=0; for(int i=0;i<n;++i) for(int j=0;j<n;++j) A[AN++]=make_pair(Length(p[j]-p[i]),make_pair(i,j)); sort(A,A+AN); double res=0.0; for(int i=AN-1;i>=0;--i){ int x=A[i].second.first, y=A[i].second.second; f[x].set(y); f[y].set(x); if((f[x]&f[y]).count()>0){ res=A[i].first/2; break; } } printf("%.20lf\n", res);// for(;;); return 0;}
0 0
- CF 333E Summer Earnings
- CF 333E Summer Earnings
- Codeforces 333E Summer Earnings
- codeforces 333E Summer Earnings
- 【Codeforces Round #194 (Div. 1)】Codeforces 333E Summer Earnings
- cf Summer sell-off
- cf-e
- CF 333E 计算几何+bitset优化
- BUPT Summer Journey #test1 E
- BUPT Summer Journey #test2 E
- BUPT Summer Journey #test3 E
- BUPT Summer Journey #test4 E
- BUPT Summer Journey #test5 E
- BUPT Summer Journey #test6 E
- BUPT Summer Journey #test7 E
- BUPT Summer Journey #test8 E
- BUPT Summer Journey #test11 E
- SDKD Summer Team Contest E
- Android开发之WebView详解
- quartz简单配置
- 学习hadoop总结(1)
- cocos KeyBoard
- linux删除满足条件的文件
- CF 333E Summer Earnings
- 【更新】.NET用户界面控件Nevron Open Vision v2016.1发布!
- 今天碰到个大小写敏感问题
- vijos P1134 算24点 题解
- Win7环境下如何开启802.1X 无线网络认证
- WebService学习总结(一)——WebService的相关概念
- Swift枚举
- 字母重排
- Swift基础三