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
", max(topa, topb));
    return 0;
}
原文地址:https://www.cnblogs.com/zufezzt/p/5203476.html