hdu6127Hard challenge(极角排序)
来源:互联网 发布:2016国内旅游数据 编辑:程序博客网 时间:2024/06/05 07:28
Hard challenge
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1385 Accepted Submission(s): 589
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
一些点在平面上,问如何让通过源点的线能经过最多的点点连成的边?
例子:(1,1)=1,(1,-1,)=1两个点在平面上,从原点出发,做垂直他们的连线线段(权值为点点乘积)就有了1。
这一类的题都可看做极角排序题,先对所以的点做极角排序(与x轴的夹角),然后对整个平面的点做与x轴的夹角计算,超过180度的额外计算
+2*PI,最后统计穿过的点点的边权值,计算出最大的的穿过量。
/** by z_guibin*/#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>#include <cmath>#include <iostream>#define N 50010const double PI=acos(-1);using namespace std;struct node{ int vla; double arg;}p[2*N];long long sum[2*N];int cmp(node a,node b){ return a.arg<b.arg;}int main(){ int t,n; scanf("%d",&t); while(t--) { long long tot=0; scanf("%d",&n); for(int i=1;i<=n;i++) { int x,y; scanf("%d %d %d",&x,&y,&p[i].vla); tot+=p[i].vla; p[i].arg=atan2(y,x); } sort(p+1,p+n+1,cmp); long long ans=0; for(int i=1;i<=n;i++) { p[i+n]=p[i]; p[i+n].arg+=2*PI; } for(int i=1;i<=2*n;i++) { sum[i]=sum[i-1]+p[i].vla; } int st=1; for(int i=1;i<=n;i++) { while(p[st].arg-p[i].arg<PI) { st++; } long long x=sum[st-1]-sum[i-1]; ans=max(ans,x*(tot-x)); } printf("%lld\n",ans); } return 0;}再贴一个额外的代码
#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespace std;const int MAX = 5e4 + 10;typedef long long LL;struct node{ int v,x,y; double o;}st[MAX];bool cmp(node i,node j) { return i.o < j.o; }void solve(int n){ LL ans = 0,l = 0,r = 0; for(int i = 0; i < n; i++) if(st[i].x < 0) l += st[i].v; else r += st[i].v; ans = l * r; for(int i = 0; i < n; i++){ if(st[i].x < 0) r += st[i].v, l -= st[i].v; else r -= st[i].v, l += st[i].v; ans = max(ans,l * r); } printf("%lld\n",ans);}int main(){ int T; scanf("%d",&T); while(T--){ int n; scanf("%d",&n); for(int i = 0; i < n; i++) scanf("%d %d %d",&st[i].x,&st[i].y,&st[i].v),st[i].o = 1.0 * st[i].y / st[i].x; sort(st,st + n,cmp); solve(n); } return 0;}来自http://blog.csdn.net/WYK1823376647/article/details/77236911
阅读全文
0 0
- hdu6127Hard challenge(极角排序)
- hdu6127Hard challenge(思维+扫描)
- HDU 6127 Hard challenge(极角排序+模拟)
- HDU6127 Hard challenge 极角排序|暴力
- HDU 6127 Hard challenge【极角排序】
- HDU 6127 Hard challenge (极角排序+二分, 2017 Multi-Univ Training Contest 7)
- HDU 6127 Hard challenge(极角排序+枚举点)
- HDU 6127 Hard challenge 计算几何 极角排序
- hdu6127-!!多校7&极角排序&问题转化-Hard challenge
- 解题报告:HDU_6127:Hard challenge (极角排序)
- HDU 6127 Hard challenge(级角排序)
- hdu6127 Hard challenge 2017多校第七场1008 计算几何 极角排序+双指针
- 2017杭电多校第七场1008 Hard challenge(级角排序)HDU 6127
- LCM Challenge(最小公倍数)
- LCM Challenge(数论)
- LCM Challenge(暴力)
- challenge(一)前言
- Hard challenge(hdu6127)
- A
- C语言的一些知识点
- vs2010+opencv3.0.0 环境配置 (以及配置技巧)
- POJ2749 Building roads【2-SAT】
- HDU 1179 Ollivanders: Makers of Fine Wands since 382 BC.(二分图匹配+匈牙利算法)
- hdu6127Hard challenge(极角排序)
- OSG 事件处理机制 类图
- java集合2
- HDU
- Velocity快速入门教程-脚本语法详解(转)
- mysql 区分大小写 mysql安装目录 数据文件目录
- CSS备忘录
- jquery 复制元素,并修改属性,追加到另一个元素后面
- 关于android studio进行NDK编译生成.so文件