Hard challenge

思路

通过极角排序,这里通过修改后,所有点的角度在[0,2π)[0, 2 \pi)[0,2π)之间,

然后O(n)O(n)O(n)扫一趟,对当前在的级角加上π\piπ就是我们要找的角度了,这里通过二分来实现查找。

接下来就只要通过前缀和思想来得到这个最大值了。

假设我们当前所在的是iii,因为角度在[0,2π)[0, 2\pi)[0,2π)所以我们查找的jjj的下标可能会有两种情况:

1:j > i,这个时候有连续的一段区间[l, j]是属于一个集合。

2:j < i,这个时候有连续的一段区间[j + 1, i - 1]是属于一个集合,

所以我们只要特判这两种情况即可。

代码

/*Author : lifehappy
*/
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>using namespace std;typedef long long ll;const double pi = acos(-1.0);
const double eps = 1e-5;
const double inf = 1e100;int Sgn(double x) {return x < -eps ? -1 : x > eps;
}struct Vector {double x, y, angle;int w;bool operator < (Vector &a) const {return x < a.x;}void print() {printf("%f %f\n", x, y);}void read() {scanf("%lf %lf", &x, &y);}Vector(double _x = 0, double _y = 0) : x(_x), y(_y) {}double mod() {return sqrt(x * x + y * y);}double mod2() {return x * x + y * y;}Vector operator + (const Vector &a) {return Vector(x + a.x, y + a.y);}Vector operator - (const Vector &a) {return Vector(x - a.x, y - a.y);}double operator * (const Vector &a) {return x * a.x + y * a.y;}double operator ^ (const Vector &a) {return x * a.y - y * a.x;}Vector Rotate(double &angle) {return Vector(x * cos(angle) - y * sin(angle), x * sin(angle) + y * cos(angle));}Vector operator << (const double &a) {return Vector(x * a, y * a);}Vector operator >> (const double &a) {return Vector(x / a, y / a);}
};typedef Vector Point;double Dis_pp(Point a, Point b) {return sqrt((a - b) * (a - b));
}double Angle(Vector a, Vector b) {double ans = atan2(a ^ b, a * b);if(ans < 0) ans += 2 * pi;return ans;// return atan2(a ^ b, a * b);
}double To_lefttest(Point a, Point b, Point c) {return (b - a) ^(c - a);
}int Toleft_test(Point a, Point b, Point c) {return Sgn((b - a) ^ (c - a));
}struct Line {Point st, ed;Line(Point _st = Point(0, 0), Point _ed = Point(0, 0)) : st(_st), ed(_ed) {}bool operator < (const Line &t) {return st.x < t.st.x;}void read() {scanf("%lf %lf %lf %lf", &st.x, &st.y, &ed.x, &ed.y);}
};bool Parallel(Line a, Line b) {return Sgn((a.st - a.ed) ^ (b.st - b.ed)) == 0;
}bool Is_cross(Line a, Line b) {return Toleft_test(a.st, a.ed, b.st) * Toleft_test(a.st, a.ed, b.ed) <= 0 && Toleft_test(b.st, b.ed, a.st) * Toleft_test(b.st, b.ed, a.ed) <= 0;
}Point Cross_point(Line a, Line b) {if(!Is_cross(a, b)) {return Point(inf, inf);}else {double a1 = fabs(To_lefttest(a.st, a.ed, b.st)), a2 = fabs(To_lefttest(a.st, a.ed, b.ed));return ((b.st << a2) + (b.ed << a1)) >> (a1 + a2);}
}Point Shadow(Line a, Point b) {Point dir = a.ed - a.st;return a.st + (dir << (((b - a.st) * dir) / dir.mod2()));
}Point Reflect(Line a, Point b) {return (Shadow(a, b) << 2) - b;
}bool inmid(double a, double b, double x) {if(a > b) swap(a, b);return Sgn(x - a) >= 0 && Sgn(b - x) >= 0;
}bool Point_in_line(Line a, Point b) {if(Toleft_test(a.st, a.ed, b) != 0) return false;return inmid(a.st.x, a.ed.x, b.x) && inmid(a.st.y, a.ed.y, b.y);
}double Dis_lp(Line a, Point b) {Point h = Shadow(a, b);if(Point_in_line(a, h)) {return Dis_pp(h, b);}return min(Dis_pp(a.st, b), Dis_pp(a.ed, b));
}double Dis_ll(Line a, Line b) {if(Is_cross(a, b)) return 0;return min({Dis_lp(a, b.st), Dis_lp(a, b.ed), Dis_lp(b, a.st), Dis_lp(b, a.ed)});
}double Area(vector<Point> p) {int n = p.size();double ans = 0;for(int i = 0; i < n; i++) {ans += p[i] ^ p[(i + 1) % n];}return 0.5 * ans;
}bool cmp(Point a, Point b) {return a.angle < b.angle;
}const int N = 5e4 + 10;Point a[N];ll value[N];int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int T;scanf("%d", &T);while(T--) {int n;scanf("%d", &n);for(int i = 1; i <= n; i++) {a[i].read();scanf("%d", &a[i].w);a[i].angle = Angle(Point(1, 0), Point(a[i].x, a[i].y));}ll sum = 0, ans = 0;sort(a + 1, a + 1 + n, cmp);for(int i = 1; i <= n; i++) {value[i] = value[i - 1] + a[i].w;sum += a[i].w;}for(int i = 1; i <= n; i++) {double now = a[i].angle, need = now + pi;if(need > 2 * pi) need -= 2 * pi;int l = 1, r = n;while(l < r) {int mid = l + r + 1 >> 1;if(a[mid].angle > need) r = mid - 1;else l = mid;}if(a[l].angle < need) l++;l--;if(l >= i) {ans = max(ans, (sum - value[l] + value[i - 1]) * (value[l] - value[i - 1]));}else {ans = max(ans, (sum - value[i - 1] + value[l]) * (value[i - 1] - value[l]));}}printf("%lld\n", ans);}return 0;
}

HDU 6127 Hard challenge(极角 + 二分)相关推荐

  1. HDU 6127 Hard challenge

    题目链接 题目意思 平面上有(n)个点,已知每个点的坐标为((x,y)),以及该点的权值为(val),任意两点之间可以连接成一条不经过原点的边,该边的权值是两个端点的权值的乘积.现在要求画一条经过原点 ...

  2. HDU - 6070 Dirt Ratio (二分 + 线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6070 题目大意:给定一个序列a,对于任何一个区间 [l,r],它的"Dirt Ratio&q ...

  3. hdu 2295 Radar 重复覆盖+二分

    题目链接 给m个雷达, n个城市, 以及每个城市的坐标, m个雷达里只能使用k个, 在k个雷达包围所有城市的前提下, 求最小半径. 先求出每个雷达到所有城市的距离, 然后二分半径, 如果距离小于二分的 ...

  4. hdu 3622 Bomb Game【二分+2-SAT+tarjan】

    用read()会挂 二分半径,显然最优的是所有原都用这个最小半径,然后2-SAT把相交的圆建图,跑tarjan判一下可行性即可 #include<iostream> #include< ...

  5. hdu 1150 Machine Schedule (经典二分匹配)

    //A组n人 B组m人 //最多有多少人匹配 每人仅仅有匹配一次 # include<stdio.h> # include<string.h> # include<alg ...

  6. hdu 5179(bfs打表+二分)

    beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. HDU Problem - 6383 p1m2(二分)

    题目链接 Problem Description 度度熊很喜欢数组!!我们称一个整数数组为稳定的,若且唯若其同时符合以下两个条件:1. 数组里面的元素都是非负整数.2. 数组里面最大的元素跟最小的元素 ...

  8. HDU Problem - 1969 Pie(二分,精度)

    题目链接 Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pi ...

  9. HDU Problem - 3763 CD(二分)

    题目链接 Problem Description Jack and Jill have decided to sell some of their Compact Discs, while they ...

最新文章

  1. 自定义UISearchBar外观
  2. Access和SQL server开启表间关系,并实现更新或删除母表数据自动更新或删除子表数据...
  3. 线程安全与锁优化(思维导图)
  4. [云炬创业基础笔记] 第四章测试12
  5. 安装ubuntu 13.04
  6. 基于 C++ POCO 库封装的异步多线程的 CHttpClient 类
  7. java obj1 = obj2_无障碍assertEquals(Object obj1,Object obj2),想怎么比较就怎么比较!! [ 光影人像 东海陈光剑 的博客 ]...
  8. 阿迪达斯asp.net sql购物商城计算机设计网站作品
  9. hdu 2295(DLX+二分)
  10. 热点聚焦:企业上ERP之前是否需要先进行流程梳理?
  11. matlab分割txt数据,MATLAB批量分割txt数据
  12. windows10鼠标指针_如何在Windows 10中更轻松地查看鼠标指针
  13. 易知大学“大数据挖掘与分析(Python)”免费学习平台
  14. 二极管工作原理讲解(转载)
  15. 深度学习数据增强方法总结
  16. 阿里云服务器如何升级公网带宽
  17. 01 【初识Django】
  18. 【Ceph 】Async 网络通信源代码分析--研读
  19. cocos2d-xnbsp;图片纹理优…
  20. php 原理 淘口令 解密_淘口令解析 - VX_super19911115 - 博客园

热门文章

  1. 忍“乳”负重,身材好的女孩子究竟有多不容易?我从科学的角度算出来了……...
  2. 谈谈女友卸妆后的感受?
  3. 这些数学趣图,数学老师看了后会怎么想?
  4. 每日一笑 | 程序员的日常,这也太真实了......
  5. 从数学入手,3招打破机器学习的边界
  6. android http 三次 握手,面试解析:3次握手与4次挥手
  7. 小手拍拍机器人_幼儿园互动儿歌游戏,小朋友瞬间变听话!
  8. mysql分析日志_MYSQL 索引(三)--- SQL日志分析
  9. java collator_Java Collator compare(String, String)用法及代码示例
  10. css中的单位换算_金蝶ERP入门教程:动态换算率及辅助计量单位的应用