Codechef Cleaning Tables

本文介绍了一种解决餐厅中服务员高效清洁桌子的问题,通过跟踪顾客的用餐顺序并选择最晚再次点餐的顾客礼貌让座,从而实现最小次数的桌子清洁。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description

Haku has been newly hired by Chef to clean tables at his restaurant. So whenever a customer wants a table, Haku must clean it.
But Haku happens to be a lazy boy. So in the morning, when the restaurant is opened, all the tables are dirty from night before.
The customer don't leave the table unless they are politely requested to do so. And customers can order meal later again. So if they were already having a table, they can be served on the same table [Haku doesn't have to clean :)]. But if they don't have a table then they must be given some table [Haku must clean :(]
The restaurant has N tables. When a customer requires a table, he/she can occupy any unoccupied table. However if all tables are occupied, then Haku is free to ask politely any customer to leave his/her table. And the freed table can be given to the waiting customer.
Now Chef has the psychic ability to tell the order of customer meal requests for the entire day. Given this list, help Haku find the minimum number of times he has to clean the tables.

Input


First line contains integer T, number of test cases.
First line of each test case contains 2 integers N, number of tables and M, number of customer orders. Followed by M integers on next line, which is the order in which customers ask for meal. Customers are referenced by integer C.

Output

For each test case output the minimum number of times Haku must clean the table(s).

Constraints

1 ≤ T ≤ 100
1 ≤ N ≤ 200
1 ≤ M ≤ 400
1 ≤ C ≤ 400

Example

Input:

4
2 4
1 2 3 4
3 2
4 1
3 6
1 2 1 3 4 1
3 5
1 2 1 3 4

Output:

4
2
4
4

Explanation

Example case 1. In the starting all tables i.e. 2 tables are unoccupied. When customer 1 asks for table, he can be given any of the 2 tables. Haku has to clean either of the table. Next customer 2 can occupy the other free table. Haku must clean second time. When customer 3 comes Haku can ask either customer 1 or 2 to leave. Suppose he asks customer 1 to leave. Then he has to clean table for the third time. When customer 4 comes, Haku can ask customer 2 or 3 to leave. In either case Haku will have to clean the table for the fourth time. Phew!!
Example case 4. Suppose the tables are listed as [-, -, -]. A possible optimal order of allocating tables can be [1, -, -] -> [1, 2, -] -> [1, 2, -] -> [1, 2, 3] -> [4, 2, 3]. So Haku will have to clean table for order no. 1, 2, 4 and 5. That is 4 times.

题解

一道傻题,打错一个字母,查了两个小时……毕竟是弱啊。

每次请出“下一次点菜”顺序最靠后的就好 。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int T,n,m,a[500];
int head[500],nx[500],seat[500],pd[500];
void init()
{
	memset(head,0,sizeof(head));
	memset(nx,0,sizeof(nx));
	scanf("%d%d",&n,&m);
	int i;
	for(i=1;i<=m;i++) scanf("%d",&a[i]);
	for(i=m;i>0;i--)
	   {if(head[a[i]]==0) {head[a[i]]=i; nx[i]=9999;}
	    else {nx[i]=head[a[i]]; head[a[i]]=i;}
	   }
}
void work()
{
	int i,j,maxl,w,top=0,ans=0;
	memset(pd,0,sizeof(pd));
	for(i=1;i<=m;i++)
	   {if(pd[a[i]]==1)
	       {for(j=0;j<top;j++)
		       {if(a[seat[j]]==a[i])
			       {seat[j]=i; break;}
			   }
		   }
		else if(pd[a[i]]==0&&top<n)
		   {ans++; seat[top]=i; top++; pd[a[i]]=1;}
		else if(pd[a[i]]==0&&top>=n)
		   {maxl=-99;
		    for(j=0;j<top;j++)
		       {if(nx[seat[j]]>maxl)
			       {maxl=nx[seat[j]]; w=j;}
			   }
			pd[a[seat[w]]]=0; pd[a[i]]=1; ans++; seat[w]=i;
		   }
	   }
	printf("%d\n",ans);
}
int main()
{
	scanf("%d",&T);
	while(T--)
	   {init(); work();}
	return 0;
}

### 自然语言处理中的数据清洗技术 在自然语言处理(Natural Language Processing, NLP)领域,数据清洗是一个至关重要的环节。它直接影响到后续模型训练的质量以及最终的应用效果。以下是几种常见的NLP数据清洗技术和最佳实践: #### 文本标准化 文本标准化是指将原始文本转换成统一的形式以便于进一步分析。这通常包括以下几个方面: - **大小写统一**:将所有字符转换为小写字母以减少不必要的差异[^1]。 - **移除特殊字符和标点符号**:删除那些可能干扰算法理解语义的非字母数字字符。 ```python import re def clean_text(text): text = text.lower() # 转换为小写 text = re.sub(r'[^\w\s]', '', text) # 移除非单词字符 return text ``` #### 去重与去噪 去除重复的数据条目可以提高计算效率并降低存储需求。此外,还需要注意剔除无关噪声,比如HTML标签、URL链接或者广告信息等内容。 ```python from bs4 import BeautifulSoup def remove_html_tags(text): soup = BeautifulSoup(text, 'html.parser') stripped_text = soup.get_text() return stripped_text ``` #### 缺失值填充 对于存在空白字段的情况,则需考虑采用适当策略来填补这些空缺位置,从而保持整个数据集的一致性和完整性。 #### 归一化/词形还原(Lemmatization & Stemming) 通过应用词干提取(stemming)或词形还原来简化词语形式至其基本形态,有助于减少词汇变体带来的复杂度[^2]。 ```python from nltk.stem import WordNetLemmatizer lemmatizer = WordNetLemmatizer() def lemmatize_words(words): lemma_list = [] for word in words.split(): lemma_word = lemmatizer.lemmatize(word) lemma_list.append(lemma_word) return " ".join(lemma_list) ``` #### 数据压缩优化 为了节省内存空间及加快运算速度,在不影响核心业务逻辑的前提下尽可能精简输入资料规模不失为明智之举[^3]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值