地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6127

题目:

Hard challenge

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 813    Accepted Submission(s): 329

Problem Description
There are n points on the plane, and the ith points has a value vali, and its coordinate is (xi,yi). It is guaranteed that no two points have the same coordinate, and no two points makes the line which passes them also passes the origin point. For every two points, there is a segment connecting them, and the segment has a value which equals the product of the values of the two points. Now HazelFan want to draw a line throgh the origin point but not through any given points, and he define the score is the sum of the values of all segments that the line crosses. Please tell him the maximum score.
 
Input
The first line contains a positive integer T(1≤T≤5), denoting the number of test cases.
For each test case:
The first line contains a positive integer n(1≤n≤5×104).
The next n lines, the ith line contains three integers xi,yi,vali(|xi|,|yi|≤109,1≤vali≤104).
 
Output
For each test case:
A single line contains a nonnegative integer, denoting the answer.
 
Sample Input
2
2
1 1 1
1 -1 1
3
1 1 1
1 -1 10
-1 0 100
 
Sample Output
1
1100
 
Source
 
思路:极角排序后扫描线
 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; struct Point
{
LL x,y,v;
}pt[K],st;
LL cross(const Point &po,const Point &ps,const Point &pe)
{
return (ps.x-po.x)*(pe.y-po.y)-(pe.x-po.x)*(ps.y-po.y);
}
bool cmp(const Point &ta,const Point &tb)
{
return cross(st,ta,tb)>;
}
int main(void)
{
int t,n;cin>>t;
while(t--)
{
int se;
LL s1=,s2=,ans=,mx=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%lld%lld%lld",&pt[i].x,&pt[i].y,&pt[i].v);
pt[i+n].x=-pt[i].x;
pt[i+n].y=-pt[i].y;
pt[i+n].v=;
s2+=pt[i].v;
}
if(n==) {printf("0\n");continue;}
sort(pt,pt+*n,cmp);
s1+=pt[].v;
for(int i=;i<*n;i++)
if(cross(st,pt[],pt[i])<)
{
se=i-;break;
}
else
s1+=pt[i].v;
s2-=s1;
mx=ans=s1*s2;
for(int i=,r=se;i<se;i++)
{
ans+=-pt[i].v*s2+(s1-pt[i].v)*pt[i].v;
s2+=pt[i].v,s1-=pt[i].v;
while(r+<*n&&cross(st,pt[i],pt[r+])>=)
{
r++;
ans+=-pt[r].v*s1+(s2-pt[r].v)*pt[r].v;
s1+=pt[r].v,s2-=pt[r].v;
}
mx=max(mx,ans);
}
printf("%lld\n",mx);
}
return ;
}

hdu6127 Hard challenge的更多相关文章

  1. 【极角排序】【扫描线】hdu6127 Hard challenge

    平面上n个点,每个点带权,任意两点间都有连线,连线的权值为两端点权值之积.没有两点连线过原点.让你画一条过原点直线,把平面分成两部分,使得直线穿过的连线的权值和最大. 就把点极角排序后,扫过去,一侧的 ...

  2. 2017 Multi-University Training Contest - Team 7

    HDU6121 Build a tree 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6121 题目意思:一棵 n 个点的完全 k 叉树,结点标号从 ...

  3. CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

    1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort    暴力枚举,水 1.题意:n*m的数组, ...

  4. The Parallel Challenge Ballgame[HDU1101]

    The Parallel Challenge Ballgame Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...

  5. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  6. acdream.LCM Challenge(数学推导)

     LCM Challenge Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  7. [codeforces 235]A. LCM Challenge

    [codeforces 235]A. LCM Challenge 试题描述 Some days ago, I learned the concept of LCM (least common mult ...

  8. iOS 网络请求中的challenge

    这里有一篇文章,请阅读,感谢作者!http://blog.csdn.net/kmyhy/article/details/7733619 当请求的网站有安全认证问题时,都需要通过 [[challenge ...

  9. CodeForces Gym 100500A A. Poetry Challenge DFS

    Problem A. Poetry Challenge Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

随机推荐

  1. CAEmitterCell 和 CAEmitterLayer具体解释

    一.在 UIKit 中,粒子系统由两部分组成: 1·      一个或多个  CAEmitterCells :发射器电池能够看作是单个粒子的原型(比如,一个单一的粉扑在一团烟雾).当散发出一个粒子,U ...

  2. [NOIP 2014复习]第二章:搜索

    一.深度优先搜索(DFS) 1.Wikioi 1066引水入城 题目描写叙述 Description 在一个遥远的国度,一側是风景秀美的湖泊,还有一側则是漫无边际的沙漠.该国的行政 区划十分特殊,刚好 ...

  3. 分页技巧_测试并继续改进分页用的QueryHelper辅助对象

    分页技巧_测试并继续改进分页用的QueryHelper辅助对象 QueryHelper.java /** * 用于辅助拼接HQL语句 */ public class QueryHelper { pri ...

  4. 将java项目发布到本地的linux虚拟机上

    1.首先安装虚拟机,这里就不介绍了. 2.然后要我下载了一个WinSCP用于windows和虚拟机之间的文件传输. 首先获得虚拟机的ip: 必须保持连接, 如果断开ip就是这样的 3.传输文件 将jd ...

  5. [libwww-perl]——POST方法的使用

    libwww-perl是我在学习varnish的时候遇到的一个工具. 具体libwww-perl是干什么的,可以参考官网https://github.com/libwww-perl/libwww-pe ...

  6. 【BZOJ3894】文理分科 最小割

    [BZOJ3894]文理分科 Description 文理分科是一件很纠结的事情!(虽然看到这个题目的人肯定都没有纠结过) 小P所在的班级要进行文理分科.他的班级可以用一个n*m的矩阵进行描述,每个格 ...

  7. android how to deal with data when listview refresh

    如何解决listview数据刷新,下拉刷新,上拉加载更多时,图片不闪烁. 在Activity的onResume()方法中将adaper和listView重新再绑定一次. listView.setAda ...

  8. vue里监听安卓的物理返回键

    Hybrid App中,原生内嵌H5单页,由于安卓是有物理返回键的,按安卓物理返回键的时候会返回到上一个路由. 实际中需求是:当有弹层的时候,按物理返回键是关闭弹层,是页面的时候才执行返回上一个路由, ...

  9. jenkins提交SVN文件

    需求背景: 公司有内网和外网两台SVN服务器,都需要维护相同的配置文件,但是我们想能否在内网修改配置文件后同时提交到外网SVN服务器上. 开发人员操作步骤 1.开发人员在IDE中checkout内网c ...

  10. PowerDesigner概念模型与物理模型相互转换及导出数据字典

    最近公司项目竣工,验收完成后,把整体平台的所有文档都写清楚,找包发给甲方,由于本人是维护数据库工作,依上面要求,必须编写<数据库设计说明书>里面格式包含三个部分:概念模型.物理模型.数据字 ...