日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 6127 Hard challenge(极角 + 二分)

發布時間:2023/12/4 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 6127 Hard challenge(极角 + 二分) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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(极角 + 二分)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。