Codeforces 828 A Restaurant Tables

本文介绍了一个关于餐厅座位安排的编程题,通过直接模拟的方法解决顾客用餐需求及座位分配的问题,确保尽可能多地接纳顾客。

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

题目地址:http://codeforces.com/contest/828/problem/A
题意:你有一家餐厅,有单人桌和双人桌,给你一串序列,告诉你来的人的个数和顺序,你要按他的条件来安排座位,问你有多少人被拒绝用餐。
一个人来的位置的优先级

1° 有单人桌
2° 有双人桌
3° 有单人坐的双人座
4° 离开

两个人来的位置的优先级

1° 有双人桌
2° 离开
思路:直接模拟

#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define LL long long 
#define N 200100
#define M 50010
#define inf 0x3f3f3f3f
using namespace std;
const LL mod = 1e9 + 7;
const double eps = 1e-9;
int num;
int main() {
    cin.sync_with_stdio(false);
    int n, a, b, c, sum;
    while (cin >> n >> a >> b) {
        c = 0;
        sum = 0;
        for (int i = 0; i < n; i++) {
            cin >> num;
            if (num == 1) {
                if (a > 0) {
                    a--;
                }
                else if (b > 0) {
                    b--;
                    c++;
                }
                else if (c > 0) {
                    c--;
                }
                else {
                    sum++;
                }
            }
            else {
                if (b > 0) {
                    b--;
                }
                else {
                    sum+=2;
                }
            }
        }
        cout << sum << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值