LINK

题意:给出n个点,每个点有个权值,可以和任意另外一点构成线段,值为权值积。现问过原点的直线中交所有线段的权值和的最大值,注意直线必不经过点。

思路:直线可以将点集分为两侧,此时的权值为两侧点的乘积。而且由于是过原点的直线,所以不用暴力枚举两个点了...直接极角排序,这里我原先的极角排序有点小问题,最后还是找的别人的,以(0,x)为最小极角的。

然后前缀和权值以便分组求积。

枚举点,与原点相连作直线,然后以枚举点的对称点,二分找到最大的在它顺时针侧的点,然后注意要注意枚举点是否包含的两种情况,这样分成两部分求积即可。

/** @Date    : 2017-08-16 13:18:05
* @FileName: 1008.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 5e4+20;
const double eps = 1e-6; struct point
{
LL x, y, v;
point(){}
point(LL _x, LL _y, LL _v):x(_x),y(_y),v(_v){}
point(LL _x, LL _y):x(_x),y(_y){}
point operator -(const point &b) const
{
return point(x - b.x, y - b.y);
}
LL operator *(const point &b) const
{
return x * b.x + y * b.y;
}
LL operator ^(const point &b) const//少了个LL WA 3发
{
return x * b.y - y * b.x;
}
}; int sign(double x)
{
if(fabs(x) < eps)
return 0;
if(x < 0)
return -1;
else return 1;
} LL xmult(point p1, point p2, point p0)
{
return (p1 - p0) ^ (p2 - p0);
} LL distc(point a, point b)
{
return sqrt((double)((b - a) * (b - a)));
} point p[N];
LL sum[N]; int cmp(point a, point b)//
{
int t = xmult(a, b, point(0, 0));
if(a.y * b.y <= 0)
{
if(a.y > 0 || b.y > 0)
return a.y < b.y;
if(a.y == 0 && b.y == 0)
return a.x < b.x;
}
return xmult(a, b, point(0,0)) > 0; } int cmp1(const point &a, const point &b) //以(x,0)为基准点(最小极角)
{
if (a.y == 0 && b.y == 0 && a.x*b.x <= 0)return a.x>b.x;
if (a.y == 0 && a.x >= 0 && b.y != 0)return true;
if (b.y == 0 && b.x >= 0 && a.y != 0)return false;
if (b.y*a.y <= 0)return a.y>b.y;
return xmult(a,b, point(0,0)) > 0 || (xmult(a,b,point(0,0)) == 0 && a.x < b.x);
} int bina(int x, int l, int r)
{
int ans = -1;
point ops = point(-p[x].x, -p[x].y);
while(l <= r)
{
int mid = (l + r) >> 1;
if(cmp1(ops, p[mid]) != 1)
{
l = mid + 1;
ans = mid;
}
else r = mid - 1;
}
return ans;
} int main()
{
int T;
cin >> T;
while(T--)
{
MMF(sum);
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++)
{
LL x, y, v;
scanf("%lld%lld%lld", &x, &y, &v);
p[i] = point(x, y, v);
}
sort(p + 1, p + n + 1, cmp1);
/*for(int i = 1; i <= n; i++)
printf("%lf %lf\n", p[i].x, p[i].y);*/
LL ans = 0;
for(int i = 1; i <= n; i++)
sum[i] = sum[i - 1] + p[i].v; for(int i = 1; i <= n; i++)
{
if(p[i].y >= 0)
{
int r = bina(i, i + 1, n);
if(r == -1)
r = i;
LL res1 = (sum[n] - (sum[r] - sum[i - 1])) * (sum[r] - sum[i - 1]);
LL res2 = (sum[n] - (sum[r] - sum[i])) * (sum[r] - sum[i]);
ans = max(max(res1, res2), ans);
//cout << ans <<"r "<< r << endl;
}
else
{
int l = bina(i, 1, i);
if(l == -1)
l = 0;
LL res1 = (sum[n] - (sum[i] - sum[l])) * (sum[i] - sum[l]);
LL res2 = (sum[n] - (sum[i - 1] - sum[l])) * (sum[i - 1] - sum[l]);
ans = max(max(res1, res2), ans);
//cout <<i <<"~" << res1 << " l: " << l<<endl;
}
}
printf("%lld\n", ans);
}
return 0;
}
/*
999
9 0 1 7
1 0 8
0 -1 9
-1 0 10
1 1 2
0 0 1
1 -1 4
-1 1 5
-1 -1 3
1.000000 0.000000
0.000000 0.000000
1.000000 1.000000
0.000000 1.000000
-1.000000 1.000000
-1.000000 0.000000
-1.000000 -1.000000
0.000000 -1.000000
1.000000 -1.000000
*/

HDU6127 简单几何 暴力二分的更多相关文章

  1. poj3977 - subset - the second time - 暴力 + 二分

    2017-08-26 11:38:42 writer:pprp 已经是第二次写这个题了,但是还是出了很多毛病 先给出AC代码: 解题思路: 之前在培训的时候只是笼统的讲了讲怎么做,进行二分对其中一边进 ...

  2. Python下opencv使用笔记(二)(简单几何图像绘制)

    简单几何图像一般包含点.直线.矩阵.圆.椭圆.多边形等等.首先认识一下opencv对像素点的定义. 图像的一个像素点有1或者3个值.对灰度图像有一个灰度值,对彩色图像有3个值组成一个像素值.他们表现出 ...

  3. Codeforces 935 简单几何求圆心 DP快速幂求与逆元

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  4. Codeforces Round #622 (Div. 2) C1. Skyscrapers (easy version)(简单版本暴力)

    This is an easier version of the problem. In this version n≤1000n≤1000 The outskirts of the capital ...

  5. 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea

    题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...

  6. Crossed ladders---poj2507(二分+简单几何)

    题目链接:http://poj.org/problem?id=2507   题意就是给你x y c求出?的距离: h1 = sqrt(x*x-d*d); h2 = sqrt(y*y-d*d); (h1 ...

  7. lightoj1062【几何(二分)】

    其实就应该想到,哪有那么简单让你直接搞出答案的几何题啊:(而且很有可能是二分? 题意: 有两个梯子,一个靠在左边墙上,一个靠在右边墙上,长度分别为 x 和 y,他们的交点距离地面高度是 c,求两个梯子 ...

  8. Codeforces Round #367 (Div. 2) A B C 暴力 二分 dp(字符串的反转)

    A. Beru-taxi time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  9. Subsequence(暴力+二分)

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10875   Accepted: 4493 Desc ...

随机推荐

  1. 敏捷开发 Scrum 综述

    敏捷开发 Scrum 综述 这一星期学习了敏捷开发,然后阅读了相关的书籍,从网上查找了很多相关的资料,对敏捷开发scrum有了更加深刻了理解,对敏捷开发做了如下总结: 一.什么是敏捷开发? 敏捷开发提 ...

  2. spark作用流程

    原文:https://www.cnblogs.com/asura7969/p/8441471.html https://blog.csdn.net/xu__cg/article/details/700 ...

  3. Swift-闭包使用及解决循环引用问题

    Swift中闭包使用参考OC中block使用,基本一致 // 闭包类型 首先写(参数列表)->(返回值类型) func loadData(callBack : (jsonData:String) ...

  4. QCryptographicHash实现哈希值计算,支持多种算法

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QCryptographicHash实现哈希值计算,支持多种算法     本文地址:http: ...

  5. Distributed transactions in Spring, with and without XA

    While it's common to use the Java Transaction API and the XA protocol for distributed transactions i ...

  6. 【C++】为多态基类声明virtual析构函数

    来自<Effective C++>条款07:为多态声明virtual析构函数 当derived class对象经由一个base class指针被删除,而该base class带着一个non ...

  7. Fiddler绕过前端直接和后台进行交互

    测试需求:有一个功能,允许用钻石兑换金币,假设1钻石=1金币,前端控制一次至少兑换10个,最多100个,后台不做验证. 测试方案:输入10,也就是告诉前端我要兑换10个金币,等前端验证通过之后,截取要 ...

  8. 【前端学习笔记01】JavaScript源生判断数据类型的方法

    原始类型(值类型):Undefined.Null.Number.String.Boolean: 对象类型(引用类型):Object: typeof  可以识别标准类型,null外(返回Object): ...

  9. 第120天:移动端-Bootstrap基本使用方法

    一.Bootstrap使用 1.搭建Bootstrap页面骨架及项目目录结构 ``` ├─ /weijinsuo/ ··················· 项目所在目录 └─┬─ /css/ ···· ...

  10. Exception异常 自定义异常

    public class Exception extends Throwable Exception 类及其子类是 Throwable 的一种形式,它指出了合理的应用程序想要捕获的条件. public ...