HDU 1171 Big Event in HDU

题目:HDU-1085

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

题目:

Big Event in HDU

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 31958    Accepted Submission(s): 11183


Problem Description
Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.
The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).
 

Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 -- the total number of different facilities). The next N lines contain an integer V (0<V<=50 --value of facility) and an integer M (0<M<=100 --corresponding number of the facilities) each. You can assume that all V are different.
A test case starting with a negative integer terminates input and this test case is not to be processed.
 

Output
For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.
 

Sample Input
  
  
2 10 1 20 1 3 10 1 20 2 30 1 -1
 

Sample Output
  
  
20 10 40 40
 

题目的意思是现有n个物品,每个物品价值为v数量为m,怎么样分成价值最接近的两堆,每一堆价值多少。

额,这个题我还是用了母函数做的,这个构造的多项式以价值为指数,和其他的一样,只不过在得出结果以后我先筛选出非0的结果,排序以后再一个个比较哪个最接近,数据比较小所以也还好,没超时。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<cstdio>
using namespace std;
const int maxn= 250005;
int a[maxn],b[maxn];
int n;
int v,m,t;
int counts;
int maxNum,ans1,ans2;
int main(){
	while(cin>>n){
		if(n<0) break;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		cin>>v>>m;
		for(int i=0;i<=m;i++)
			a[i*v]=1;
		t=v*m;
		for(int i=1;i<n;i++){
			cin>>v>>m;
			t+=v*m;
			for(int j=0;j<=t;j++)
				for(int k=0;k<=v*m;k+=v)
					b[j+k]+=a[j];
			for(int j=0;j<=t;j++){
				a[j]=b[j];
				b[j]=0;
			}
		} //以上为构建母函数得出结果
		counts=0;
		for(int i=1;i<=t;i++){                        //筛选非0解
			if(a[i]!=0)
				b[counts++]=i;
		}
		sort(b,b+counts);                           //排序,其实不排也没什么
		maxNum=maxn;
		for(int i=0;i<counts;i++){                  //记住保证大的一堆在前面
			if(t-b[i]>=b[i]){
				if(t-b[i]-b[i]<maxNum){
					maxNum=t-b[i]-b[i];
					ans1=t-b[i];
					ans2=b[i];
				}
			}
			else{
				if(2*b[i]-t<maxNum){
					maxNum=2*b[i]-t;
					ans1=b[i];
					ans2=t-b[i];
				}
			}
		}
		cout<<ans1<<" "<<ans2<<endl;
	}
	return 0;
}

good good study, day day up!

飞思卡尔智能车竞赛是一项备受关注的科技赛事,旨在激发学生的创新和实践能力,尤其是在嵌入式系统、自动控制和机器人技术等关键领域。其中的“电磁组”要求参赛队伍设计并搭建一辆能够自主导航的智能车,通过电磁感应线圈感知赛道路径。本压缩包文件提供了一套完整的电磁组智能车程序,这是一套经过实战验证的代码,曾在校级比赛中获得第二名的优异成绩。 该程序的核心内容可能涉及以下关键知识点: 传感器处理:文件名“4sensor”表明车辆配备了四个传感器,用于获取环境信息。这些传感器很可能是电磁感应传感器,用于探测赛道上的导电线圈。通过分析传感器信号的变化,车辆能够判断自身的行驶方向和位置。 数据采集与滤波:在实际运行中,传感器读数可能受到噪声干扰,因此需要进行数据滤波以提高精度。常见的滤波算法包括低通滤波、高斯滤波和滑动平均滤波等,以确保车辆对赛道的判断准确无误。 路径规划:车辆需要根据传感器输入实时规划行驶路径。这可能涉及PID(比例-积分-微分)控制、模糊逻辑控制或其他现代控制理论方法,从而确保车辆能够稳定且快速地沿赛道行驶。 电机控制:智能车的驱动通常依赖于直流电机或无刷电机,电机控制是关键环节。程序中可能包含电机速度和方向的调节算法,如PWM(脉宽调制)控制,以实现精准的运动控制。 嵌入式系统编程:飞思卡尔智能车的控制器可能基于飞思卡尔微处理器(例如MC9S12系列)。编程语言通常为C或C++,需要掌握微控制器的中断系统、定时器和串行通信等功能。 软件架构:智能车软件通常具有清晰的架构,包括任务调度、中断服务程序和主循环等。理解和优化这一架构对于提升整体性能至关重要。 调试与优化:程序能够在比赛中取得好成绩,说明经过了反复的调试和优化。这可能涉及代码效率提升、故障排查以及性能瓶颈的识别和解决。 团队协作与版本控制:在项目开发过程中,团队协作和版本控制工具(如Git)的应用不可或缺,能够保
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值