hihoCoder 1225 向日葵(凸包)
来源:互联网 发布:table.sort 排序算法 编辑:程序博客网 时间:2024/04/28 02:17
题目链接:hihoCoder 1225 向日葵
枚举每条线段称为凸包边界的概率。注意一对点中有1个在线段左边*0.5,0个在线段左边*0,2个都在线段左边*1。最后答案要除4,因为枚举的两个点也要算概率。
#include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <complex>#include <algorithm>using namespace std;typedef pair<int,int> pii;typedef long long ll;const double pi = 4 * atan(1);const double eps = 1e-10;inline int dcmp (double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; }inline double getDistance (double x, double y) { return sqrt(x * x + y * y); }inline double torad(double deg) { return deg / 180 * pi; }struct Point {int id;double x, y, ang;Point (double x = 0, double y = 0, double ang = 0, int id = 0): x(x), y(y), ang(ang), id(id) {}void read () { scanf("%lf%lf", &x, &y); }bool operator < (const Point& u) const { return dcmp(x - u.x) < 0 || (dcmp(x-u.x)==0 && dcmp(y-u.y) < 0); }bool operator > (const Point& u) const { return u < *this; }bool operator == (const Point& u) const { return dcmp(x - u.x) == 0 && dcmp(y - u.y) == 0; }bool operator != (const Point& u) const { return !(*this == u); }bool operator <= (const Point& u) const { return *this < u || *this == u; }bool operator >= (const Point& u) const { return *this > u || *this == u; }Point operator + (const Point& u) { return Point(x + u.x, y + u.y); }Point operator - (const Point& u) { return Point(x - u.x, y - u.y); }Point operator * (const double u) { return Point(x * u, y * u); }Point operator / (const double u) { return Point(x / u, y / u); }double operator * (const Point& u) { return x*u.y - y*u.x; }};typedef Point Vector;const int maxn = 1005;int N, V[maxn], C1, C2;Point A[maxn], B[maxn], T[maxn * 4];double getCross (Vector a, Vector b) { return a.x * b.y - a.y * b.x; }double getArea (Point a, Point b, Point c) { return getCross(b - a, c - a) / 2; }inline int cmp(const Point& a, const Point& b) { return a.ang < b.ang; }void add (int x) {V[x]++;if (V[x] == 1)C1++;elseC1--, C2++;}void del (int x) {V[x]--;if (V[x] == 0)C1--;elseC2--, C1++;}double solve(Point* P) {double ans = 0;for (int i = 0; i < N; i++) {int sz = 0;for (int j = 0; j < N; j++) if (i != j) {T[sz++] = Point(A[j].x, A[j].y, atan2(A[j].y-P[i].y, A[j].x-P[i].x), j);T[sz++] = Point(B[j].x, B[j].y, atan2(B[j].y-P[i].y, B[j].x-P[i].x), j);}for (int j = 0; j < sz; j++) {T[sz + j] = T[j];T[sz + j].ang += 2 * pi;}sort(T, T + 2 * sz, cmp);int r = 0;C1 = C2 = 0;memset(V, 0, sizeof(V));add(T[r].id);for (int j = 0; j < sz; j++) {del(T[j].id);while (T[r+1].ang - T[j].ang < pi) add(T[++r].id);//while (C1 + 2 * C2 != r - j);int c = C1 - V[T[j].id];if (c + C2 != N - 2) continue;ans += getArea(Point(0, 0), P[i], T[j]) * pow(0.5, c);}}return ans;}int main () {while (scanf("%d", &N) == 1) {for (int i = 0; i < N; i++) A[i].read(), B[i].read();double ans = solve(A) + solve(B);printf("%lf\n", ans / 4);}return 0;}
0 0
- hihoCoder 1225 向日葵(凸包)
- hihoCoder 1225 向日葵
- hihoCoder挑战赛14 向日葵 (极角扫描)
- 向日葵
- 远程桌面连接教程(teamview&向日葵).doc
- hihocoder 1582 : Territorial Dispute (计算几何 凸包)(2017 北京网络赛E)
- 2017北京网络赛 && hihocoder 1582 Territorial Dispute(凸包)
- 2017北京网赛hihocoder #1582 : Territorial Dispute 【凸包】
- hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
- deepin使用向日葵远程控制(修改run.sh)
- hihoCoder挑战赛12 顺子(hihocoder 1177)
- 向日葵的人生
- 做个向日葵族
- Oray向日葵远程控制
- 听见向日葵的微笑
- 向日葵的寓意
- 向日葵vpn vip怎么样
- 花生壳,向日葵,花生棒
- Ardiuno开发版Mac驱动安装
- Unity 游戏移植到 Windows10 之路 -- 环境搭建
- UNITY 5.1.3 发行说明 中文版
- 字符串的交错组成
- android:SQLite--触发器详解
- hihoCoder 1225 向日葵(凸包)
- 细说java.util.HashMap
- OC随机数方法
- DFS--奇偶剪枝
- EasyUI中Messager基本使用
- Java眼中的XML---文件读取
- Spring MVC 参数传递
- C#中的空值的判断
- jQuery编程的最佳实践