CodeForces 626C Block Towers

构造AC的。左右两边都先不用6的倍数,然后哪边数字大那一边往回退一下,然后再比较哪边数字大.......直到结束

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;

const int maxn = 10000000 + 10;
int n, m;
int a[maxn];
int b[maxn];
int flag[maxn];
int topa, topb;

int main()
{
    scanf("%d%d", &n, &m);
    memset(a, 0, sizeof a);
    memset(b, 0, sizeof b);
    memset(flag, 0, sizeof flag);
    int num1 = 0, num2 = 0, num;
    int nowa = 0, nowb = 0;
    for (int aa = 0, i = 2; aa < n; i = i + 2)
    {
        if (i % 6 != 0) a[i] = 1, topa = i, aa++;
        else nowa = i;
    }
    for (int aa = 0, i = 3; aa<m; i = i + 3)
    {
        if (i % 6 != 0) b[i] = 1, topb = i, aa++;
        else nowb = i;
    }
    while (1)
    {
        if (nowa == 0 && nowb == 0) break;
        if (topa>topb)
        {
            a[topa] = 0; topa--;
            while (1)
            {
                if (b[nowa] == 0)
                {
                    a[nowa] = 1;
                    nowa = nowa - 6;
                    while (1)
                    {
                        if (a[topa]) break;
                        topa--;
                    }
                    break;
                }
                nowa = nowa - 6;
            }
        }
        else
        {
            b[topb] = 0; topb--;
            while (1)
            {
                if (a[nowb] == 0)
                {
                    b[nowb] = 1;
                    nowb = nowb - 6;
                    while (1)
                    {
                        if (b[topb]) break;
                        topb--;
                    }
                    break;
                }
                nowb = nowb - 6;
            }
        }
        while (1)
        {
            if (b[nowa]) nowa = nowa - 6;
            else break;
        }
        while (1)
        {
            if (a[nowb]) nowb = nowb - 6;
            else break;
        }
    }
    printf("%d\n", max(topa, topb));
    return 0;
}

 

转载于:https://www.cnblogs.com/zufezzt/p/5203476.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值