Restaurant Tables【CodeForces 828A】+Game of the Rows【CodeForces 839B】

感觉这两个题很像,解法相同。
Restaurant Tables
题意:给顾客安排座位,如果顾客是一个人,就安排一个位置的,如果没有就安排两个座位的,但只占一个位置。顾客是两个人就安排两个位置。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int Max=100;
int main()
{
    int n,num1,num2,k=0;
    int x,ans=0;
    while(scanf("%d%d%d",&n,&num1,&num2)!=EOF)
    {
        k=0,ans=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&x);
            if(x==1)
            {
                if(num1)
                {
                    num1--;
                }
                else if(num2)
                {
                    num2--;
                    k++;
                }
                else if(k)
                {
                    k--;
                }
                else ans+=1;
            }
            else
            {
                if(num2)
                {
                    num2--;
                }
                else ans+=2;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Game of the Rows
题意:给队伍安排座位,有2个座的和4个座的。不同的队伍不能安排到一起。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof(a))
const int Max=1e5;
const int INF=0x3f3f3f3f;
using namespace std;
int a[Max];
int main()
{
    int m,n,i;
    while(scanf("%d%d",&m,&n)!=EOF)
    {
        int sum=0;
        int sum1=m*8;
        int k=0,flag=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        if(k>m||sum>sum1)
        {
            printf("NO\n");
            continue;
        }
        int x1=m;
        int x2=m*2;
        k=0;
        sort(a,a+n);
        for(i=n-1;i>=0;i--)
        {
            while(a[i]>0)
            {
                if(x1)
                {
                    a[i]-=4;
                    x1--;
                    if(a[i]==-3)
                        x2++;
                    if(a[i]==-2)
                        k++;
                }
                else if(x2){
                    a[i]-=2;
                    x2--;
                }
                else if(k)
                {
                    a[i]-=1;
                    k--;
                }
                else {
                    flag=1;
                    break;
                }
            }
            if(flag==1)
                break;
        }
        if(flag==1)
            printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值