HDU 6127 Hard challenge(级角排序)
来源:互联网 发布:淘宝u站怎么进入 编辑:程序博客网 时间:2024/06/06 02:43
Hard challenge
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1272 Accepted Submission(s): 540
Problem Description
There are n points on the plane, and the i th 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 integern(1≤n≤5×104) .
The nextn lines, the i th line contains three integers xi,yi,vali(|xi|,|yi|≤109,1≤vali≤104) .
For each test case:
The first line contains a positive integer
The next
Output
For each test case:
A single line contains a nonnegative integer, denoting the answer.
A single line contains a nonnegative integer, denoting the answer.
Sample Input
221 1 11 -1 131 1 11 -1 10-1 0 100
Sample Output
11100
Source
2017 Multi-University Training Contest - Team 7
Recommend
liuyiding
平面直角坐标系上有n个整点,第i个点有一个点权vali,坐标为(xi,yi),其中不存在任意两点连成的直线经过原点。这些整点两两之间连有一条线段,线段的权值为其两端点的权值之积。你需要作一条过原点而不过任意一个给定整点的直线,使得和这条直线相交的线段的权值和最大。1≤n≤5×104,1≤vali≤104,∣xi∣,∣yi∣≤109。
对于一条直线,线段权值和实际上就等于其两边点权和的乘积,所以把所有点按极角排个序,然后扫一圈就好了。
以为一开始肯定要有一个直线,不妨设为x轴或者y轴,如果设为y轴的话,刚好利用了atan只能处理 -90 ~ 90的角的性质,如果以x轴的话,则要把3象限对称到1象限, 4象限对称到2象限, 排序之后, 点不变,只是点的标号变了, 模拟直线的旋转,期间不断更新就好了
y轴为中心线代码:
#include<set>#include<map>#include<cmath>#include<ctime>#include<cstdio>#include<cassert>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;const double PI=acos(-1);typedef long long ll;#define maxn 200005struct Node{double x,y,ang;int v;Node(){}Node(double x,double y,int v):x(x),y(y),v(v){}void input(){ scanf("%lf%lf%d", &x, &y, &v); ang = atan(y/x); }bool operator < (const Node &p)const{ return ang < p.ang; }}p[maxn];int n, T, v[maxn];double x[maxn],y[maxn];ll sumL,sumR,ans;int main(){ scanf("%d", &T);while (T--) { scanf("%d", &n); for(int i = 1; i <= n; i++) p[i].input(); sort(p+1,p+n+1); sumL = sumR = ans = 0; for(int i = 1; i <= n; i++) { if(p[i].x > 0) sumL += p[i].v; else sumR += p[i].v; } ans = sumL*sumR; for(int i = 1; i <= n; i++) { if (p[i].x > 0) sumL -= p[i].v, sumR += p[i].v; else sumL += p[i].v, sumR -= p[i].v; ans=max(ans, sumL*sumR); } printf("%lld\n",ans); } return 0;}
x轴为中心线代码:
#include<bits/stdc++.h>#define N 50006using namespace std;const double pi=acos(-1.0);struct point{ long long x,y,v; bool flag;}a[N];bool cmp(point x,point y){ double xx,yy; xx=atan2((double)x.y,(double)x.x); yy=atan2((double)y.y,(double)y.x); return xx<yy;}int main(){ int t,n; long long sum1=0,sum2=0; scanf("%d",&t); while(t--) { sum1=0,sum2=0; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].v); if(a[i].y<0) { sum1+=a[i].v; a[i].x*=-1; a[i].y*=-1; a[i].flag=false; } else a[i].flag=true,sum2+=a[i].v; } sort(a,a+n,cmp); long long ans=sum1*sum2; for(int i=0;i<n;i++) {// cout<<a[i].x<<" "<<a[i].y<<endl; if(a[i].flag) { sum2-=a[i].v; sum1+=a[i].v; } else { sum1-=a[i].v; sum2+=a[i].v; } ans=max(ans,sum1*sum2); } cout<<ans<<endl; } return 0;}
阅读全文
0 0
- HDU 6127 Hard challenge(级角排序)
- HDU 6127 Hard challenge【极角排序】
- HDU 6127 Hard challenge(极角排序+模拟)
- 2017杭电多校第七场1008 Hard challenge(级角排序)HDU 6127
- HDU 6127 Hard challenge(极角排序+枚举点)
- HDU 6127 Hard challenge 计算几何 极角排序
- HDU 6127 Hard challenge (极角排序+二分, 2017 Multi-Univ Training Contest 7)
- HDU 6127 Hard challenge
- hdu 6127 Hard challenge
- hdu--6127--Hard challenge
- HDU 6127 Hard challenge
- HDU 6127 Hard challenge
- hdu 6127 Hard challenge
- HDU 6127 Hard challenge
- hdu 6127 Hard challenge
- HDU 6127 Hard challenge
- HDU 6127 Hard challenge(几何)
- HDU 6127 Hard challenge(数学)
- springmvc的执行流程详解
- 网易编程题 疯狂队列
- 502 Server dropped connection
- 利用springmvc 导入导出excel
- KMP入门级别算法详解--终于解决了(next数组详解)
- HDU 6127 Hard challenge(级角排序)
- iis10配置PHP运行环境教程3
- oracle单表查询
- Java线程学习(一)线程的创建和执行
- H
- Django 多 app 同名 模版 引用
- TensorFlow学习笔记2——数据类型及简单运算
- HDU 6121 满k叉树 + 思维
- 30分钟掌握ES6/ES2015核心内容(上)