540 - Team Queue***

//提交未成功
#include <iostream>
#include <string>
#include <cstdio>
#include <sstream>
using namespace std;
const int nMax=1005;
struct Queue{
	int q[nMax];
	int front,rear;
	Queue():front(0),rear(0){}
}queue[nMax];
struct Team{
	int t[nMax];
	int n;//n表示元素个数
	Team():n(0){}
}team[nMax];
int t,n;
int getTeam(int x)
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<team[i].n;j++)
		if(team[i].t[j]==x)
			return i;
	}
	return -1;
}
void EnQueue(int u,int a)
{
	queue[u].q[queue[u].front++]=a;
}
int DeQueue()
{
	for(int i=0;i<n;i++)
	{
		for(int j=queue[i].rear;j<queue[i].front;j++)
		{
			return queue[i].q[queue[i].rear++];
		}
	}
	return -1;
}
int main()
{
	/*
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
	//*/
	int cas=0;
	while(scanf("%d",&t) && t!=0)
	{
		cas++;
		printf("Scenario #%d\n",cas);
		for(int i=0;i<t;i++)
		{
			scanf("%d",&n);
			team[i].n=n;
			for(int j=0;j<n;j++)
				scanf("%d",&team[i].t[j]);
		}
		string command;
		while(getline(cin,command) && command!="STOP")
		{
			istringstream in(command);
			string oper;
			in>>oper;
			if(oper=="ENQUEUE")
			{
				int a;
				in>>a;
				int u;
				u=getTeam(a);
				EnQueue(u,a);
			}
			else if(oper=="DEQUEUE")
			{
				int a=DeQueue();
				if(a!=-1)
				printf("%d\n",a);
			}
		}
		printf("\n");
	}
	return 0;
}

#include <iostream>
#include <cstdio>
#include <string>
#include <list>
using namespace std;
list<int> l;
int elem[1000000];//暴力求解--思想
list<int>::iterator team[1005];
int t,n;
int main()
{
	//freopen("data.in","r",stdin);
	int cas=0;
	while(scanf("%d",&t) && t)
	{
		printf("Scenario #%d\n",++cas);
		l.clear();
		for(int i=1;i<=t;i++)
		{
			team[i]=l.end();
			int n;
			scanf("%d",&n);
			for(int j=0;j<n;j++)
			{
				int a;
				scanf("%d",&a);
				elem[a]=i;
			}
		}
		string oper;
		while(cin>>oper && oper!="STOP")
		{
			if(oper=="ENQUEUE")
			{
				int b;
				scanf("%d",&b);
				if(team[elem[b]]!=l.end())
				{
					++team[elem[b]];
					team[elem[b]]=l.insert(team[elem[b]],b);
				}
				else
					team[elem[b]]=l.insert(team[elem[b]],b);
			}
			else if(oper=="DEQUEUE")
			{
				int temp;
				temp=l.front();
				if(team[elem[temp]]==l.begin())//漏写
					team[elem[temp]]=l.end();
				printf("%d\n",temp);
				l.pop_front();
			}
		}
		printf("\n");
	}
	return 0;
}

第二次做:未通过

#include <cstdio>
#include <cstring>
const int nMax=1000+10;
struct Queue
{
	int q[nMax];
	int front,rear;
}queue[nMax];
int team[1000000];//哈希表处理查找问题,会方便很多
int t;
void dequeue()
{
	for(int i=0;i<t;i++)
		if(queue[i].front!=queue[i].rear)
		{
			printf("%d\n",queue[i].q[queue[i].rear++]);
			return;
		}
}
int main()
{
	//freopen("f://data.in","r",stdin);
	int n=0;
	while(scanf("%d",&t) && t)
	{
		printf("Scenario #%d\n",++n);
		memset(team,0,sizeof(team));
		memset(queue,0,sizeof(queue));
		for(int ans=0;ans<t;ans++)
		{
			int k;
			scanf("%d",&k);
			while(k--)
			{
				int num;
				scanf("%d",&num);
				team[num]=ans;
			}
		}
		char opr[10];
		while(scanf("%s",opr))
		{
			if(strcmp(opr,"STOP")==0)
				break;
			else if(strcmp(opr,"ENQUEUE")==0)
			{
				int a;
				scanf("%d",&a);
				int pos=team[a];
				queue[pos].q[queue[pos].front++]=a;
			}
			else if(strcmp(opr,"DEQUEUE")==0)
			{
				dequeue();
			}
		}
		printf("\n");
	}
	return 0;
}


/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2022-09-21 baijinhui the first version */ #include "app_actuator.h" #if (ACTUATOR_TYPE == 25) #include <rtthread.h> #include <rtdevice.h> #include "board.h" #include <stdio.h> #include "bsp_can.h" #include "app_location.h" #include "app_chassis.h" #include "lib_inc.h" #include "app_chassis_fork.h" #include "app_qrps.h" #define DBG_TAG "actuator" #define DBG_LVL DBG_LOG #include <ulog.h> /*-------------------------外部引用-------------------------*/ /*-------------------------公共变量-------------------------*/ /*-------------------------局部变量-------------------------*/ #define Pi 3.14159265359f static struct msg_actuator_status msg1; static struct msg_actuator_ctrl msg2; static struct msg_actuator_para msg3; static struct msg_qrps_status qrpsMsg1; static struct msg_location_status locationMsg1; static struct msg_chassis_ctrl chassisMsg2; static struct msg_chassis_para chassisMsg3; static struct msg_chassis_fork_status forkMsg1; static struct msg_chassis_fork_ctrl forkMsg2; static struct rt_messagequeue mq_actuatorDriver; static char msg_pool_actuatorDriver[128]; struct rx_actuatorDriver { unsigned short int id; unsigned char cmd; unsigned short int index; unsigned char sub_index; unsigned char dat[4]; }; static unsigned int actStatus[3] = { 0 }; // 动作执行状态 static unsigned int timeCount[3] = { 0 }; //动作执行计时 static unsigned int hightNeedCal = 1; //高度需要校准 0不需要 1需要 static unsigned int slideNeedCal = 1; //横移需要校准 0不需要 1需要 static unsigned int locBiasError = 0; //上装定位偏差错误 /*-------------------------函数实现-------------------------*/ void app_actuator_status(struct msg_actuator_status *status) { RT_ASSERT(status != RT_NULL); rt_memcpy(status, &msg1, sizeof(msg1)); } void app_actuator_ctrl(struct msg_actuator_ctrl *ctrl) { RT_ASSERT(ctrl != RT_NULL); rt_memcp
03-13
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值