地址: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. [转]VC++下使用ADO操作数据库

    (1).引入ADO类 1 2 3 #import "c:program filescommon filessystemadomsado15.dll" no_namespace re ...

  2. Windows下安装Apache 2.2.21图文教程

    https://www.jb51.net/article/52086.htm 本文详细介绍了在Windows平台上安装Apache的过程,希望对初次安装Apache的朋友有所帮助. 1. 软件准备 我 ...

  3. JZOJ.5288【NOIP2017模拟8.17】球场大佬

    Description       每天下午,古猴都会去打羽毛球.但是古猴实在是太强了,他必须要到一些比较强的场去打.但是每个羽毛球场都有许多的人排着队,每次都只能上四个人,每个人都有自己的能力值,然 ...

  4. 【BZOJ2423】[HAOI2010]最长公共子序列 DP

    [BZOJ2423][HAOI2010]最长公共子序列 Description 字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字 ...

  5. 【BZOJ4873】[Shoi2017]寿司餐厅 最大权闭合图

    [BZOJ4873][Shoi2017]寿司餐厅 Description Kiana最近喜欢到一家非常美味的寿司餐厅用餐.每天晚上,这家餐厅都会按顺序提供n种寿司,第i种寿司有一个代号ai和美味度di ...

  6. Jfinal报错sql injection violation, multi-statement not allow

    Jfinal报错: com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: sql injection ...

  7. [LintCode] 寻找缺失的数

    class Solution { public: /** * @param nums: a vector of integers * @return: an integer */ int findMi ...

  8. PHP之冒号、endif、endwhile、endfor 是什么鬼?f

    解释:其实这些都是PHP的语法,只不过不常用而已,这些都是PHP流程控制的替代语法. 冒号(:)相当于是 左大括号---->{ endif.endwhile.endfor.endforeach- ...

  9. 让网站全面支持v4/v6 HTTP、HTTPS、HTTP/2最简单方法是增加Nginx反向代理服务器

    bg6cq/nginx-install: nginx install script https://github.com/bg6cq/nginx-install [原创]step-by-step in ...

  10. IE8数组不支持indexOf方法的解决办法

    在使用indexof方法之前加上以下代码就可以了. if (!Array.prototype.indexOf){           Array.prototype.indexOf = functio ...