每日ACM学习以及小水题 2013年11月3日

本文解析了两道ACM编程挑战题目,第一题通过累积求和算法解决卡片悬空长度问题;第二题利用数论原理找出特定的(n,k)组合,满足一定条件的等式,并给出完整的代码实现。

说明

为了向大神看齐,遂响应号召,每天刷一下POJ上面的水题,每天学习一点ACM,做一点ACM题目。

我相信积少成多,更相信,开头是艰难的,但是一旦走进去,就会别有一番感受,速度也会加快吧。

so ,today is the first day .


题目

第一题

POJ 1003 (传送门:http://poj.org/problem?id=1003

题目描述:

Description

How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2+1/3=5/6 card lengths. In general you can makencards overhang by 1/2+1/3+1/4+...+1/(n+1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n+1). This is illustrated in the figure below.



Input

The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.

Output

For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples.

第二题

找所有的(n, k), 满足:1+2+..+(n-1)=(n+1)+(n+2)…+k 。输出按k排序的前6个。


解答过程

第一题:简答的数学题


代码如下:
/*****  简单ACM水题 ********/

/******** written by C_Shit_Hu ************/

////////////////POJ 1003///////////////

/****************************************************************************/
/* 
求平均数。
*/
/****************************************************************************/

#include <iostream>
using namespace std;

int main()
{ 
	int i;
	float len,s;
	while(cin >> len && len != 0.00)
	{
		s = 0.0;
		for(i = 2; ; i++)
		{
			s+=1.0/i;
			if(s >= len)
				break;
		}
		cout << i-1 <<" card(s)" << endl;
	}
	return 0;
}

运行结果:


第二题:数论相关的题目

【分析过程】
整理得: n(n-1)=(k-n)(n+k+1),化简得: k2+k-2n2=0, 即n2=k(k+1)/2,
由于k和k+1互素, 因此
----要么k是完全平方数
----要么k/2是完全平方数

分别设k=m2和2m2, 枚举m

代码如下:
/*****  简单ACM水题 ********/

/******** written by C_Shit_Hu ************/

///////////////////////////////

/****************************************************************************/
/* 
找所有的(n, k), 满足:
1+2+..+(n-1)=(n+1)+(n+2)…+k
输出按k排序的前10个
*/
/****************************************************************************/

#include <iostream>
#include <cmath>
using namespace std;

bool sing(int  j)
{
	long int k, n;
	double m;
	k = j * j;
	n = k*(k+1) / 2;
	m = sqrt(n);
	if ( floor(m + 0.5) == m)
	{
	//	printf("n = %d, k = %d\n", m, k);
		cout << m << " " << k  << endl;
		return true;
	}
	else
		return false;
}

bool doub(int j)
{
	long int k, n;
	double m;
	k = 2 * j * j;
	n = k*(k+1) / 2;
	m = sqrt(n);
	if ( floor(m + 0.5) == m)
	{
		cout << m << " " << k  << endl;
		return true;
	}
	else
		return false;
}

int main( )
{
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	int i, j;
		for (i=1,j=1; i< 7 ; j++)
		{
			if(sing(j))
				i ++ ;
			if(doub(j))
				i ++ ;
		}
	return 0;
}




/******************************************************/
/********************  心得体会  **********************/
/*

*/
/******************************************************/

运行结果:


【未完待续】..............

【四轴飞行器】非线性三自由度四轴飞行器模拟器研究(Matlab代码实现)内容概要:本文围绕非线性三自由度四轴飞行器模拟器的研究展开,重点介绍基于Matlab代码实现的四轴飞行器动力学建模与仿真方法。研究构建了考虑非线性特性的飞行器数学模型,涵盖姿态动力学与运动学方程,实现了三自由度(滚转、俯仰、偏航)的精确模拟。文中详细阐述了系统建模过程、控制算法设计思路及仿真结果分析,帮助读者深入理解四轴飞行器的飞行动力学特性与控制机制;同时,该模拟器可用于算法验证、控制器设计与教学实验。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的高校学生、科研人员及无人机相关领域的工程技术人员,尤其适合从事飞行器建模、控制算法开发的研究生和初级研究人员。; 使用场景及目标:①用于四轴飞行器非线性动力学特性的学习与仿真验证;②作为控制器(如PID、LQR、MPC等)设计与测试的仿真平台;③支持无人机控制系统教学与科研项目开发,提升对姿态控制与系统仿真的理解。; 阅读建议:建议读者结合Matlab代码逐模块分析,重点关注动力学方程的推导与实现方式,动手运行并调试仿真程序,以加深对飞行器姿态控制过程的理解。同时可扩展为六自由度模型或加入外部干扰以增强仿真真实性。
基于分布式模型预测控制DMPC的多智能体点对点过渡轨迹生成研究(Matlab代码实现)内容概要:本文围绕“基于分布式模型预测控制(DMPC)的多智能体点对点过渡轨迹生成研究”展开,重点介绍如何利用DMPC方法实现多智能体系统在复杂环境下的协同轨迹规划与控制。文中结合Matlab代码实现,详细阐述了DMPC的基本原理、数学建模过程以及在多智能体系统中的具体应用,涵盖点对点转移、避障处理、状态约束与通信拓扑等关键技术环节。研究强调算法的分布式特性,提升系统的可扩展性与鲁棒性,适用于多无人机、无人车编队等场景。同时,文档列举了大量相关科研方向与代码资源,展示了DMPC在路径规划、协同控制、电力系统、信号处理等多领域的广泛应用。; 适合人群:具备一定自动化、控制理论或机器人学基础的研究生、科研人员及从事智能系统开发的工程技术人员;熟悉Matlab/Simulink仿真环境,对多智能体协同控制、优化算法有一定兴趣或研究需求的人员。; 使用场景及目标:①用于多智能体系统的轨迹生成与协同控制研究,如无人机集群、无人驾驶车队等;②作为DMPC算法学习与仿真实践的参考资料,帮助理解分布式优化与模型预测控制的结合机制;③支撑科研论文复现、毕业设计或项目开发中的算法验证与性能对比。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注DMPC的优化建模、约束处理与信息交互机制;按文档结构逐步学习,同时参考文中提及的路径规划、协同控制等相关案例,加深对分布式控制系统的整体理解。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值