HDU 6127 Hard challenge

探讨了在平面上给定多个带权值点的情况下,如何通过原点绘制一条不经过这些点的直线,以最大化该直线所穿过线段的权值之和。通过排序和扫描算法高效求解。

Hard challenge

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 812    Accepted Submission(s): 328


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(1T5) , denoting the number of test cases.
For each test case:
The first line contains a positive integer  n(1n5×104) .
The next  n  lines, the  i th line contains three integers  xi,yi,vali(|xi|,|yi|109,1vali104) .
 

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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6127

题意:平面上n个点,每个点有一个权值且每个点的坐标都是不同的,已知任意两点确定的直线不经过原点,问原点做一条不经过给定点的直线中,与直线相交的线段的最大权值之和是多少?线段的权值等于它两端点权值的乘积。

解题思路:这道题是昨天多校第七场中的一道AC人数居第三的题目,但是我们队在昨天的比赛中没有做出来,主要原因在我,理解错题意把队友给坑了,如果那时候把题目仔细看清楚再跟他讲的话或许还有希望A,但没这么多如果,所以就老老实实补题吧。其实理解题意再充分利用给定的条件是不难的,只要把n个点(y轴上的点特判一下)的极角(斜率也是一样的)按从小到大的顺序排序,排序后将n个点扫描一遍就好了。(可以理解为从y轴逆时针扫描),这里有一个技巧,直线左边的点可以与右边的任意一点连成线段,所以线段权值之和就可以变成左边点权值之和乘上右边点权值之和。(x1*y1)+(x1*y2)+(x2*y1)+(x2*y2)=(x1+x2)*(y1+y2)。

AC代码:

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN = 50000 + 10;
const double PI = acos(-1.0);
struct Point{//定义点的结构体 
	int x,y; //坐标 
	long long val; //权值 
	double ang; //点的极角 
};
Point point[MAXN];
int N;
bool cmp(Point p1,Point p2) //按点的极角(斜率)升序排序 
{
	return p1.ang<p2.ang;
}
void solve()
{
	long long lsum=0; //过原点直线的左边区域 
	long long rsum=0; //过原点直线的右边区域 
	long long ans; //答案 
	sort(point,point+N,cmp); //排序 
	for(int i=0;i<N;i++) //初始时假定直线为y轴 
	{
		if(point[i].x>=0) rsum+=point[i].val; //直线右边,即x右半轴 
		else lsum+=point[i].val; //直线左边,即x的左半轴 
	}
	ans=lsum*rsum; //左边权值乘上右边权值 
	for(int i=0;i<N;i++) //遍历N个点 
	{
		if(point[i].x>=0) //当前点如果之前在直线右边,那么现在变为直线左边的点 
		{
			rsum-=point[i].val;
			lsum+=point[i].val;
		}
		else //当前点如果之前在直线左边,同理 
		{
			rsum+=point[i].val;
			lsum-=point[i].val;
		}
		ans=max(ans,lsum*rsum); //更新ans 
	}
	printf("%lld\n",ans);
}
int main(void)
{
	int T; //测试组数 
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&N);
		for(int i=0;i<N;i++)
		{
			scanf("%d%d%lld",&point[i].x,&point[i].y,&point[i].val);
			if(point[i].x==0) //y轴上的点特判 
			{
				if(point[i].y<0) point[i].ang=-PI/2.0;
				else point[i].ang=PI/2.0;
			}
			else point[i].ang=atan(point[i].y*1.0/point[i].x); //计算点的极角 
		}
		solve();
	}
	return 0;
}


内容概要:本文详细阐述了车载以太网通信栈中两个核心模块——以太网接口(EthIf)与以太网驱动(Eth)的功能需求与技术规范。重点介绍了EthIf在上下层协议间的数据转发、硬件抽象、VLAN支持、PDU配置、队列调度、睡眠管理及性能计数器等方面的设计要求;同时深入描述了Eth模块在硬件初始化、工作模式切换、时间戳支持、DMA传输、流量整形与调度、帧抢占等底层驱动功能的技术实现要点。整体围绕车载高可靠性、低延迟、可配置性强的通信需求展开,体现了现代汽车电子架构对高性能网络通信的支持能力。; 适合人群:从事汽车电子、车载网络通信、ECU开发的工程师,尤其是熟悉AUTOSAR架构并希望深入了解以太网协议栈底层机制的研发人员;具备一定嵌入式系统和网络通信基础的技术人员。; 使用场景及目标:①用于设计和实现符合车规级要求的以太网通信栈;②理解EthIf与Eth在车载网络中的角色分工与协作机制;③掌握中断/轮询模式、VLAN处理、时间同步、流量调度、帧抢占等关键技术在实际系统中的应用;④支持高实时性应用场景如自动驾驶、多传感器融合等的网络架构设计。; 阅读建议:建议结合AUTOSAR标准文档及相关硬件手册进行对照学习,重点关注模块接口定义与状态机行为,结合实际项目需求进行配置与验证,并注意软硬件协同设计中的时序与资源管理问题。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值