UVa 12108 Extraordinarily Tired Students

本文深入探讨了信息技术领域的多个细分技术领域,包括前端开发、后端开发、移动开发、游戏开发、大数据开发等,旨在为读者提供全面的技术知识概览。

When a student is too tired, he can't help sleeping in class, even if his favorite teacher is right here in front of him. Imagine you have a class of extraordinarily tired students, how long do you have to wait, before all the students are listening to you and won't sleep any more? In order to complete this task, you need to understand how students behave.

When a student is awaken, he struggles for a minutes listening to the teacher (after all, it's too bad to sleep all the time). After that, he counts the number of awaken and sleeping students (including himself). If there are strictly more sleeping students than awaken students, he sleeps for b minutes. Otherwise, he struggles for another a minutes, because he knew that when there is only very few sleeping students, there is a big chance for them to be punished! Note that a student counts the number of sleeping students only when he wants to sleep again.

Now that you understand each student could be described by two integers a and b , the length of awaken and sleeping period. If there are always more sleeping students, these two periods continue again and again. We combine an awaken period with a sleeping period after it, and call the combined period an awaken-sleeping period. For example, a student with a = 1 and b = 4 has an awaken-sleeping period of awaken-sleeping-sleeping-sleeping-sleeping. In this problem, we need another parameter c (1$ \le$c$ \le$a + b) to describe a student's initial condition: the initial position in his awaken-sleeping period. The 1st and 2nd position of the period discussed above are awaken and sleeping, respectively.

Now we use a triple (abc) to describe a student. Suppose there are three students (2, 4, 1), (1, 5, 2) and (1, 4, 3), all the students will be awaken at time 18. The details are shown in the table below.

\epsfbox{p3785.eps}

Table 1. An example

Write a program to calculate the first time when all the students are not sleeping.

Input 

The input consists of several test cases. The first line of each case contains a single integer n (1$ \le$n$ \le$10) , the number of students. This is followed by n lines, each describing a student. Each of these lines contains three integers abc (1$ \le$ab$ \le$5) , described above. The last test case is followed by a single zero, which should not be processed.

Output 

For each test case, print the case number and the first time all the students are awaken. If it'll never happen, output -1.

Sample Input 

3 
2 4 1 
1 5 2 
1 4 3 
3 
1 2 1 
1 2 2 
1 2 3
0

Sample Output 

Case 1: 18 
Case 2: -1

第一种方法,当所有人的位置出现循环时,则判断输出为-1
第二种方法,当模拟次数到达100000时,则判断输出为-1
疑问:第一种方法为TLE, 第二种方法为AC
#include "stdio.h"
#include "string.h"


// stu[x][0] : a, stu[x][1] : b, stu[x][2]: 现在的位置
int stu[20][3];
// 保存上一论的结果,查看是否构成循环
int flag[20][20];

int main()
{
	int n;
	int g_count = 0;
	while(scanf("%d", &n) == 1 && n != 0)
	{
		memset(stu, 0, sizeof(stu));
		memset(flag, 0, sizeof(flag));
		g_count++;
		int count = 0;
		while(count < n)
		{
			int a, b, c;
			scanf("%d%d%d",&a,&b,&c);
			stu[count][0] = a, stu[count][1] = b; stu[count][2] = c;
			count++;		
		}
		int round_count = 1;
		while(1)
		{
			// 检查是否全醒	
			int i;
			for(i = 0; i < count; i++)
			{
				if(stu[i][2] > stu[i][0])
					break;
			}		
			// 如果全醒,返回结果
			if(i == count)
			{
				printf("Case %d: %d\n", g_count, round_count);
				break;
			}
			/*
			// 检查是否构成循环
			for(i = 0; i < count; i++)
			{
				if(stu[i][2] != flag[i][stu[0][2]])
					break;
			}		
			// 如果构成循环,则返回-1
			if(i == count)
			{
				printf("Case %d: -1\n", g_count);
                                break;
			}
			// 如果不构成循环,记录下来
			for(i = 0; i < count; i++)
				flag[i][stu[0][2]] = stu[i][2];
			*/// 更新每个学生状态
			int tmp_s[20];
			memset(tmp_s, 0, sizeof(tmp_s));
			for(i = 0; i < count; i++)
			{
				//如果学生要睡
				if(stu[i][2] == stu[i][0])
				{
					// 计算睡觉的学生人数
					int sleep_count = 0;
					for(int j = 0; j < count; j++)
					{
						if(stu[j][2] > stu[j][0])
							sleep_count++;
					}	
					// 如果睡觉人数不大于醒着人数,学生重新醒着
					if(sleep_count <= (count - sleep_count))
						tmp_s[i] = 1;
					// 如果不是,学生睡觉
					else
						tmp_s[i] = stu[i][2] + 1;
				}
				// 如果学生在醒着
				else if(stu[i][2] < stu[i][0])
					tmp_s[i] = stu[i][2] + 1;
				// 如果学生在睡着
				else
				{
					if((stu[i][2] + 1) > (stu[i][0] + stu[i][1]))
						tmp_s[i] = 1;
					else
						tmp_s[i] = stu[i][2] + 1;
				}
			}
			// 将所有状态更新
			for(i = 0; i < count; i++)
				stu[i][2] = tmp_s[i];
			round_count++;
			if(round_count > 100000)
			{
				printf("Case %d: -1\n", g_count);
				break;
			}
		}		
	}
	return 0;	
}


基于STM32 F4的永磁同步电机无位置传感器控制策略研究内容概要:本文围绕基于STM32 F4的永磁同步电机(PMSM)无位置传感器控制策略展开研究,重点探讨在不依赖物理位置传感器的情况下,如何通过算法实现对电机转子位置和速度的精确估计与控制。文中结合嵌入式开发平台STM32 F4,采用如滑模观测器、扩展卡尔曼滤波或高频注入法等先进观测技术,实现对电机反电动势或磁链的估算,进而完成无传感器矢量控制(FOC)。同时,研究涵盖系统建模、控制算法设计、仿真验证(可能使用Simulink)以及在STM32硬件平台上的代码实现与调试,旨在提高电机控制系统的可靠性、降低成本并增强环境适应性。; 适合人群:具备一定电力电子、自动控制理论基础和嵌入式开发经验的电气工程、自动化及相关专业的研究生、科研人员及从事电机驱动开发的工程师。; 使用场景及目标:①掌握永磁同步电机无位置传感器控制的核心原理与实现方法;②学习如何在STM32平台上进行电机控制算法的移植与优化;③为开发高性能、低成本的电机驱动系统提供技术参考与实践指导。; 阅读建议:建议读者结合文中提到的控制理论、仿真模型与实际代码实现进行系统学习,有条件者应在实验平台上进行验证,重点关注观测器设计、参数整定及系统稳定性分析等关键环节。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值