求助
查看原帖
求助
315448
whdywjd楼主2023/6/8 12:09

rt. TLE#4

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define lf long double
#define eps 1e-8
#define inf (1ll << 60)
#define pi 3.1415926535897932
#define _pb push_back
#define _mp make_pair
#define _1 first
#define _2 second
#define MAX_N 314

using namespace std;

int id[MAX_N * MAX_N];
int n;
int a[MAX_N];
bitset<MAX_N> cro;

void MAIN()
{
    cin >> n;
    int sum = 0;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i];
        if(!id[a[i]])
            id[a[i]] = i;
        for(int j = a[i] + 1; j <= sum; j++)
            if(!id[j] && id[j - a[i]])
                id[j] = i;
    }
    //printf("E\n");
    if((sum & 1) || !id[sum / 2])
    {
        cout << "First" << endl;
        while(1)
        {
            int x, y;
            for(x = 1; x <= n && !a[x]; x++);
            cout << x << endl;
            fflush(stdout);
            cin >> y;
            if(y <= 0)
                return;
            int v = min(a[x], a[y]);
            a[x] -= v, a[y] -= v;
        }
    }
    else
    {
        for(int i = sum / 2; i; i -= a[id[i]])
            cro.set(id[i]);
        cout << "Second" << endl;
        fflush(stdout);
        while(1)
        {
            int x, y;
            cin >> x;
            if(x <= 0)
                return;
            for(y = 1; y <= n && (cro[x] == cro[y] || !a[y]); y++);
            cout << y << endl;
            int v = min(a[x], a[y]);
            a[x] -= v, a[y] -= v;
        }
    }
}

void CLEAR()
{
    ;
}

void EXPERIMENT()
{
    ;
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    EXPERIMENT();
    int T = 1;
    while(T--)
    {
        MAIN();
        CLEAR();
    }
    return 0;
}
2023/6/8 12:09
加载中...