Codeforces Round #423 A. Restaurant Tables

来源:互联网 发布:手机怎么申请淘宝号码 编辑:程序博客网 时间:2024/05/21 10:07

题目网址: Codeforces Round #423 A. Restaurant Tables

题意分析:

  • 有n组人来吃饭, 每组人包含一个人或两个人
  • 饭馆有 a张 单人桌, b张双人桌
  • 若是一个人,则坐单人桌, 但当没单人桌时, 双人桌充足时, 将会一人独占坐双人桌, 当没有双人桌时, 这个人会坐在双人桌空着的另一个位置. 如果都没位置了, 则拒绝该客人
  • 若是两个人, 有 双人桌, 则坐下, 无双人桌, 则拒绝客人.

主要用一个ab变量来记录一人独占双人桌数目即可, 详情见代码

代码:

#include <iostream>#include <cstring>using namespace std;const int SIZE = 2e5+6;int main(int argc, char const *argv[]){    int n, a, b, group, ab;    int cnt;    while (~scanf("%d %d %d", &n, &a, &b))    {        cnt = 0;        ab = 0;        for (int i = 0; i < n; ++i)        {            scanf("%d", &group);            if(group & 1)            { // 表示来1个人                if(a)                {                    --a;                }                else if(b)                {                    --b;                    ++ab;                }                else if(ab)                {                    --ab;                }                else                 {                    ++cnt;                }            }            else            { // 表示来2个人                if(b)                {                    --b;                }                else                 {                    cnt += 2;                }            }        }        printf("%d\n", cnt);    }    return 0;}