Codeforces #828A: Restaurant Table 题解

本文介绍了一个简单的模拟问题解决方法:如何根据顾客需求和现有资源(单人桌、双人桌及可拼桌的数量),模拟顾客进入餐厅并尽可能安排就坐的过程。通过逐个处理顾客请求,确保每一步都尽可能满足顾客的座位需求。

按照题目的要求进行模拟即可

单人来先选单人桌,没有单人桌选双人桌,cnt双人座-1,cnt可拼桌+1 没有双人桌 cnt可拼桌-1 没有可拼桌ans++

双人来选双人桌,没有双人桌ans+2

注意题目问最后有多少人而不是多少组被拒绝,所以双人组被拒ans+2

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <sstream>
#include <bitset> 
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define ld long double
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

int main ()
{
	int n,a,b,x;
	scanf("%d%d%d",&n,&a,&b);
	int res=0,ra=a,rb=b,cnt=0;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if (x==1)
		{
			if (ra>0)
			{
				ra--;
				continue;
			}
			if (rb>0)
			{
				rb--;
				cnt++;
				continue;
			}
			if (cnt>0)
			{
				cnt--;
				continue;
			}
			res++;
		}
		else
		{
			if (rb>0)
			{
				rb--;
				continue;
			}
			res+=2;
		}
	}
	cout<<res<<endl;
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值