http://poj.org/problem?id=1456&&并查集

本文介绍了一种算法,用于在限定时间内优化商品销售策略,最大化收益。通过按商品利润排序并考虑销售截止时间,算法能计算出每组商品的最佳销售方案及其利润。实例分析了如何将算法应用于具体商品集合,从而实现最大化的销售利润。
Description

A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the sale begins. Each product takes precisely one unit of time for being sold. A selling schedule is an ordered subset of products Sell ≤ Prod such that the selling of each product x∈Sell, according to the ordering of Sell, completes before the deadline dx or just when dx expires. The profit of the selling schedule is Profit(Sell)=Σx∈Sellpx. An optimal selling schedule is a schedule with a maximum profit.
For example, consider the products Prod={a,b,c,d} with (pa,da)=(50,2), (pb,db)=(10,1), (pc,dc)=(20,2), and (pd,dd)=(30,1). The possible selling schedules are listed in table 1. For instance, the schedule Sell={d,a} shows that the selling of product d starts at time 0 and ends at time 1, while the selling of product a starts at time 1 and ends at time 2. Each of these products is sold by its deadline. Sell is the optimal schedule and its profit is 80.



Write a program that reads sets of products from an input text file and computes the profit of an optimal selling schedule for each set of products.

Input

A set of products starts with an integer 0 <= n <= 10000, which is the number of products in the set, and continues with n pairs pi di of integers, 1 <= pi <= 10000 and 1 <= di <= 10000, that designate the profit and the selling deadline of the i-th product. White spaces can occur freely in input. Input data terminate with an end of file and are guaranteed correct.
Output

For each set of products, the program prints on the standard output the profit of an optimal selling schedule for the set. Each result is printed from the beginning of a separate line.
Sample Input

4 50 2 10 1 20 2 30 1

7 20 1 2 1 10 3 100 2 8 2
5 20 50 10

Sample Output

80

185

AC代码:

#include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #define MAX 10005 using namespace std; struct product { int a,b; }A[MAX]; int sun[MAX]; bool operator<(const product &x,const product &y) {return x.a>y.a;} int find(int a) { if(a!=sun[a]) sun[a]=find(sun[a]); return sun[a]; } int main() { int n,i,sum,flag[MAX],b,max; while(scanf("%d",&n)!=EOF) { max=0; for(i=0;i<n;i++) { scanf("%d%d",&A[i].a,&A[i].b); if(max<A[i].b) max=A[i].b; } for(i=0;i<=max;i++) sun[i]=i; sort(A,A+n); memset(flag,0,sizeof(flag)); sum=0; for(i=0;i<n;i++) { if(!flag[A[i].b]) { sum+=A[i].a; flag[A[i].b]=1; sun[A[i].b]=A[i].b-1; } else { b=find(A[i].b); if(b) { sum+=A[i].a; flag[b]=1; sun[b]=b-1; } } } printf("%d\n",sum); } return 0; }

代码二:

#include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #define MAX 10005 #define FOR(i,s,t) for(int i=(s);i<=(t);++i) using namespace std; struct product { int a,b; }A[MAX]; int sun[MAX]; bool operator<(const product &x,const product &y) {return x.a>y.a;} int find(int a) { //if(a!=sun[a]) //sun[a]=find(sun[a]); //return sun[a]; while(a!=sun[a]) a=sun[a]; return a; } int main() { int n,flag[MAX],m; while(scanf("%d",&n)!=EOF) { m=0; FOR(i,0,n-1) { scanf("%d%d",&A[i].a,&A[i].b); m=max(m,A[i].b); } FOR(i,0,m) {sun[i]=i; flag[i]=0; } sort(A,A+n); int sum=0; FOR(i,0,n-1) { if(!flag[A[i].b]) { sum+=A[i].a; flag[A[i].b]=1; sun[A[i].b]=A[i].b-1; } else { int b=find(A[i].b); if(b) { sum+=A[i].a; flag[b]=1; sun[b]=b-1; } } } printf("%d\n",sum); } return 0; }
思路:首先按利润从大到小排序,然后判断在该物品卖出的截止日期,如果截止日期已被占用,就向前寻找。



内容概要:本文围绕六自由度机械臂的人工神经网络(ANN)设计展开,重点研究了正向与逆向运动学求解、正向动力学控制以及基于拉格朗日-欧拉法推导逆向动力学方程,并通过Matlab代码实现相关算法。文章结合理论推导与仿真实践,利用人工神经网络对复杂的非线性关系进行建模与逼近,提升机械臂运动控制的精度与效率。同时涵盖了路径规划中的RRT算法与B样条优化方法,形成从运动学到动力学再到轨迹优化的完整技术链条。; 适合人群:具备一定机器人学、自动控制理论基础,熟悉Matlab编程,从事智能控制、机器人控制、运动学六自由度机械臂ANN人工神经网络设计:正向逆向运动学求解、正向动力学控制、拉格朗日-欧拉法推导逆向动力学方程(Matlab代码实现)建模等相关方向的研究生、科研人员及工程技术人员。; 使用场景及目标:①掌握机械臂正/逆运动学的数学建模与ANN求解方法;②理解拉格朗日-欧拉法在动力学建模中的应用;③实现基于神经网络的动力学补偿与高精度轨迹跟踪控制;④结合RRT与B样条完成平滑路径规划与优化。; 阅读建议:建议读者结合Matlab代码动手实践,先从运动学建模入手,逐步深入动力学分析与神经网络训练,注重理论推导与仿真实验的结合,以充分理解机械臂控制系统的设计流程与优化策略。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值