2015年3月22日 星期日

2015/03/22 HSNU OJ Problem : 290 - [Interactive]Cave

#include "interactive/290.h"
#include <iostream>
#include <cstdio>

using namespace std;

bool OK[10000];
int ON[10000];
int Ans[10000];

int N;

int main()
{
    N = Initialize();

    for(int Ni = 0; Ni < N; Ni++)
    {
        int now = 0;

        for(int Nj = 0; Nj < N; Nj++)
            if( !OK[Nj] ) ON[Nj] = now;

        if( tryCombination(ON) != Ni );
        else now = 1-now;

        int l = 0, r = N;

        while( l+1 != r )
        {
            int mid = (l+r)/2;

            for(int Nj = 0; Nj < N; Nj++)
                if( !OK[Nj] ) ON[Nj] = 1-now;

            for(int Nj = l; Nj < mid; Nj++)
                if( !OK[Nj] ) ON[Nj] = now;

            if( tryCombination(ON) != Ni ) r = mid;
            else l = mid;
        }

        OK[l] = true;
        ON[l] = now;

        Ans[l] = Ni;
    }

    answer(ON, Ans);
}

沒有留言:

張貼留言