HDU 6127 Hard challenge (几何)
来源:互联网 发布:软件算无形资产吗 编辑:程序博客网 时间:2024/06/15 16:11
传送门:http://acm.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): 633 Accepted Submission(s): 249
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个整点,第i个点有一个点权vali,坐标为(xi,yi),其中不存在任意两点连成的直线经过原点
整点两两之间连有一条线段,线段的权值为其两端点的权值之积。你需要作一条过原点而不过任意一个给定整点的
直线,使得和这条直线相交的线段的权值和最大。
1≤n≤5×104,1≤vali≤104,∣xi∣,∣yi∣≤109。
对于一条直线,线段权值和实际上就等于其两边点权和的乘积,所以把所有点按极角排个序,然后扫一圈就好了。
感觉这个题目的数据是有点水的,很多情况并没有涉及到就能过。比如,经过原点的一条直线上的两个点应该
必须被一条直线分成两在两侧的,而在一侧充计是不对的。还有就是关于原点的话它的权值是不应该被计入的。
也没有精度问题。再就是LL的问题要注意了。解释一下:比如‘左边’权值和为L,‘右边’权值和为R,(先按着y轴为
直线分的,注意y轴的点关于x轴上下点不会在一个区域内的)当扫描一个点的时候,那在该点与原点连线上的所有
都会变动,对于一个点a而言,如果本身在左边,那么要变到右边的话,L-=a.val,R+=a.val。
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#include <queue>using namespace std;typedef long long LL;struct node{ LL x,y; LL val; double k;}point[5*10100];double get_k(LL x,LL y){ if(x==0)return -2*atan(1.0); return atan((double)y/(double)x);}bool Dir(LL x,LL y){ if(x==0) { if(y>0)return true; else return false; } if(x>0)return false; return true;}bool cmp(node a,node b){ return a.k<b.k;}int main(){ int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); LL L=0,R=0,num=0; for(int i=1;i<=n;i++) { scanf("%lld%lld%lld",&point[i].x,&point[i].y,&point[i].val); //if(point[i].x==point[i].y&&point[i].x==0)point[i].val=0; point[i].k=get_k(point[i].x,point[i].y); if(Dir(point[i].x,point[i].y))L+=point[i].val; else R+=point[i].val; } sort(point+1,point+1+n,cmp); num=L*R; for(int i=1;i<=n;) { double kk=point[i].k; while(point[i].k==kk) { if(point[i].x==0) { if(point[i].y>0) { L-=point[i].val; R+=point[i].val; } else { R-=point[i].val; L-=point[i].val; } } else if(point[i].x>0) { R-=point[i].val; L+=point[i].val; } else { R+=point[i].val; L-=point[i].val; } i++; } num=max(num,L*R); } printf("%lld\n",num); } return 0;}
阅读全文
0 0
- 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 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
- Spark SQL 之 Join 实现
- 搭建个人vpn:vps+shadowsocks
- 软碟通UltraISO 9.65.3237 【官方版+ 注册码】
- 《大型分布式网站架构设计与实践》——常见的Web攻击手段
- 视频质量分析系统VC
- HDU 6127 Hard challenge (几何)
- hadoop 二次排序join的实现
- Unity UGUI 的RectTransform参数的设置
- django 和 mysql 的连接 MySQL 查看表结构简单命令
- 聊聊操作系统-文件系统
- 原生JS封装Ajax
- 神经网络训练之数据归一化处理
- 基于CentOS搭建FTP文件服务
- 安卓开发踩坑整理