hdu 6127 计算几何模拟题(旋转扫描线)
来源:互联网 发布:三浦翔平人不好知乎 编辑:程序博客网 时间:2024/05/01 21:38
Hard challenge
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 579 Accepted Submission(s): 235
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
题意:
给出n个点,以及点上的权值,任意两条线可以连线,线上的权值是两个点的权值的乘积
题解:
容易发现,用一条线分割开后,就是两个边的和的乘积了
此时我们用极坐标排序,然后用一条射线进行扫描处理即可
队友的代码,惋惜
#include<math.h>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define MAXN 50005#define LL long longstruct Point{ LL x,y; int v; double rad; bool operator < (const Point&rhs) const { return rad < rhs.rad; }} p[MAXN];LL sum[MAXN];bool left(Point a, Point b){ return (LL)a.x*b.y - (LL)a.y*b.x >= 0;}int main(){ int n,m,T; //freopen("in.txt","r",stdin); scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%I64d%I64d%d",&p[i].x,&p[i].y,&p[i].v); p[i].rad=atan2(p[i].y, p[i].x); } sort(p,p+n); sum[0]=p[0].v; for(int i=1;i<n;i++) sum[i]=sum[i-1]+p[i].v; LL ans=0; LL L=0,R=0,cnt=0;///L为分割点,R为扫描线 while(L<n) { if(R==L){ R=(R+1)%n; cnt++; } while(R!=L&&left(p[L],p[R])) ///R不等于L并且在180度之内 { R=(R+1)%n; cnt++; } cnt--; ///分隔线旋转,原本在分隔线上的点到了右边,所以要减去 LL t1,t2; int num=L+cnt; if(num<n) { t1=sum[num]-sum[L]; t2=sum[n-1]-t1; ans=max(ans,t1*t2); } else { t1=sum[n-1]-sum[L]+sum[num-(n-1)-1]; t2=sum[n-1]-t1; ans=max(ans,t1*t2); } L++; ///分隔线旋转 } printf("%I64d\n",ans); } return 0;}
阅读全文
0 0
- hdu 6127 计算几何模拟题(旋转扫描线)
- HDU 4116 Fruit Ninja ( 计算几何 + 扫描线 )
- HDU 3867 计算几何扫描线
- hdu 4629 计算几何 扫描线 (2013多校联合)
- HDU 4998 Rotate(计算几何 绕点旋转)
- HDU 4998 Rotate(计算几何 绕点旋转)
- HDU3867 计算几何扫描线
- HDU3867 计算几何扫描线
- HDU 5017 Ellipsoid (计算几何,模拟退火)
- HDU 3644 计算几何 模拟退火
- POJ2398——Coneology(计算几何,扫描线)
- [BZOJ1845][Cqoi2005] 三角形面积并(计算几何+扫描线)
- HDU 6127 Hard challenge(计算几何)
- poj 1151 Atlantis(计算几何 扫描线)
- hdu 4998 Rotate 计算几何 点的旋转
- hdu 2876 (计算几何)
- hdu 5733 (计算几何)
- HDU-4823(计算几何)
- 【勤哲应用】用勤哲Excel服务器做人事工资管理系统
- NYISTME 1300 递推求值
- poj-2773(数论+容斥原理+二分)
- Reader 和 Writer
- Linux设备驱动模型框架分析(五)——LDDM的展现:sysfs
- hdu 6127 计算几何模拟题(旋转扫描线)
- MFC内存绘图设备封装类
- Game of the Rows CodeForces
- 【yoyo】关于java中内部类的使用
- AngularJs学习之路(九)
- LeetCode200. Number of Islands 基础dfs
- MOOC清华《面向对象程序设计》第2章:函数参数的缺省值实验
- OpenCart 3.x版本简体中文语言包安装教程
- 怪盗基德的挑战书