天天看点

Codeforces Round #423 (Div. 2)A Restaurant Tables 思维题

CF传送门

Codeforces Round #423 (Div. 2)A Restaurant Tables 思维题
Codeforces Round #423 (Div. 2)A Restaurant Tables 思维题

题意:

1. 一家餐厅有a张单人桌,b张双人桌

2. 将有n组人来餐厅就餐,每组人数1-2

3. 单人组合优先分配单人桌,其次是空的双人桌,万不得已就和别人拼桌。双人组合只能分配双人桌

4. 问餐厅拒绝的客户数量

题解:

好像没什么好说的,直接按照要求遍历一遍,用个判断语句就好了

以下是我的AC代码:

#include <iostream>

using namespace std;

const int maxn=200000+5;        //用const定义常量要不define更好
int t[maxn];

int main()
{
    int n,a,b,c=0,sum=0;        //c记录已坐有1个人的双人桌数量
    cin >> n >> a >> b;
    for(int i=1;i<=n;i++)
        cin >> t[i];
    for(int i=1;i<=n;i++){
        if(t[i]==1 && a)        //有单人桌优先放单人桌
            a--;
        else if(t[i]==2 && b)   //双人组合肯定只能放双人桌啊
            b--;
        else if(t[i]==1 && b){  //没有单人桌就放到空的双人桌
            b--;
            c++;
        }
        else if(t[i]==1 && c)   //既没有单人桌也没有空的双人桌就只能和别人拼桌啦
            c--;
        else
            sum+=t[i];          //情况之外的只能say sorry!啦
    }
    cout << sum << endl;
    return 0;
}