[XSY 1947] Goodness

题意

  给定 n 个点 $\left\{ p_i = (a_i, b_i) \right\}$ , 求 $\max_{i, j} |p_i \times p_j|$ .

  n <= 100000 .

分析

  凸包 + 三分 .

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <cctype>
 5 #include <algorithm>
 6 using namespace std;
 7 #define F(i, a, b) for (register int i = (a); i <= (b); i++)
 8 #define LL long long
 9 inline LL rd(void) {
10     LL f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == ‘-‘) f = -1;
11     LL x = 0; for (; isdigit(c); c = getchar()) x = x*10+c-‘0‘; return x*f;
12 }
13 inline LL Abs(LL x) { return x < 0 ? -x : x; }
14
15 const int N = 200005;
16
17 int n, Len;
18 struct point {
19     LL x, y;
20     friend inline point operator - (point A, point B) { return (point){ A.x - B.x, A.y - B.y }; }
21     friend inline LL det(point A, point B) { return A.x * B.y - A.y * B.x; }
22 }Origin, p[N], s[N];
23 inline bool operator < (point A, point B) { return det(A - Origin, B - Origin) > 0; }
24
25 void Build(void) {
26     int ID = 1;
27     F(i, 2, n)
28         if (p[ID].y > p[i].y || (p[ID].y == p[i].y && p[ID].x > p[i].x))
29             ID = i;
30     swap(p[1], p[ID]);
31     sort(p+2, p+n+1);
32     F(i, 1, n) {
33         while (Len >= 2 && det(p[i] - s[Len-1], s[Len] - s[Len-1]) >= 0)
34             s[Len--] = (point){ 0, 0 };
35         s[++Len] = p[i];
36     }
37 }
38
39 inline LL Calc(point A, point B) { return Abs(det(A, B)); }
40 inline LL Search(point A, int l, int r) {
41     while (r-l > 3) {
42         int _l = (l + l + r) / 3; LL ansL = Calc(A, s[_l]);
43         int _r = (l + r + r) / 3; LL ansR = Calc(A, s[_r]);
44         ansL < ansR ? l = _l : r = _r;
45     }
46     LL res = 0;
47     F(i, l, r)
48         res = max(res, Calc(A, s[i]));
49     return res;
50 }
51
52 int main(void) {
53     #ifndef ONLINE_JUDGE
54         freopen("convex.in", "r", stdin);
55     #endif
56
57     n = rd();
58     F(i, 1, n) {
59         LL G = rd(), R = rd();
60         p[i] = (point){ G, R };
61     }
62
63     Build();
64     F(i, Len+1, Len+Len)
65         s[i] = s[i - Len];
66
67     LL res = 0;
68     F(i, 1, Len)
69         res = max(res, Search(s[i], i+1, i+Len));
70     printf("%lld\n", res);
71
72     return 0;
73 }
时间: 2024-10-07 05:16:19

[XSY 1947] Goodness的相关文章

[POJ 1947]Rebuilding Roads (树形dp)

题目链接:http://poj.org/problem?id=1947 题目大意:给你一棵树,树上N个节点.问最少拆掉多少条边使得存在一个联通块,有P个节点. 树形dp,设计状态:dp[u][i]代表以u为根节点的剩下i个节点最少需要拆掉多少条边. 状态转移:dp[u][i+j] = min(dp[u][i+j],dp[u][i]+dp[v][j]-1); 其中v是u的儿子节点. 相当于在树上跑01背包,即每个儿子节点去掉剩下j个的但是要连上u-v边,或者不去掉剩下j个的. 代码: 1 impo

poj 1947(树形dp)

题意:一棵树上问你最少切掉几条边使得能分割出一个结点数正好为k的子树. 思路:dp[i][j]表示以i为根切掉j个结点最少要几条边. dp[v][j] = min(dp[v][j], dp[v][j-k] + dp[x][k]); 代码如下: 1 dp[v][j] = min(dp[v][j], dp[v][j-k] + dp[x][k]); 2 } 3 } 4 } 5 } 6 } 7 return vex[v]; 8 } 9 10 int main() 11 { 12 // freopen("

Gradle Goodness: Copy Files with Filtering

Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filtering capabilities. This means we can change the contents of the files that are copied before they reach their new destination. We use the filter() method

POJ 1947 Rebuilding Roads (树形dp 经典题)

Rebuilding Roads Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9499   Accepted: 4317 Description The cows have reconstructed Farmer John's farm, with its N barns (1 <= N <= 150, number 1..N) after the terrible earthquake last May. The

Gradle Goodness: Task Output Annotations Create Directory Automatically

Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of Gradle is incremental build support. With incremental build support a task is only executed if it is really necessary. For example if a task generate

Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects

Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects Gradle is very flexible. One of the ways to alter the build configuration is with initialization or init scripts. These are like other Gradle scripts but are executed before t

POJ 1947 Rebuilding Roads (树dp + 背包思想)

题目链接:http://poj.org/problem?id=1947 一共有n个节点,要求减去最少的边,行号剩下p个节点.问你去掉的最少边数. dp[u][j]表示u为子树根,且得到j个节点最少减去的边数. 考虑两种情况,去掉孩子节点v与去不掉. (1)去掉孩子节点:dp[u][j] = dp[u][j] + 1 (2)不去掉孩子节点:dp[u][j] = min(dp[u][j - k] + dp[v][k]) 综上就是dp[u][j] = min(dp[u][j] + 1, min(dp[

[poj 1947] Rebuilding Roads 树形DP

Rebuilding Roads Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10653 Accepted: 4884 Description The cows have reconstructed Farmer John's farm, with its N barns (1 <= N <= 150, number 1..N) after the terrible earthquake last May. The co

POJ 1947 树形DP入门题

给出N个点,N-1个关系,建出树形图,问最少减去几个边能得到节点数为P的树.典型树形DP题 dp[cur][j] :记录cur结点,要得到一棵j个节点的子树去掉的最少边数 转移方程用的背包的思想 对当前树的每一个子树进行计算 砍掉此子树:   dp[cur][j]=dp[cur][j]+1; 不砍掉:           for (l=0;l<=j;l++)  dp[cur][j]=Min(dp[cur][j],dp[cur][l]+dp[next][j-l]); 枚举从该树中留l个节点其他由新