Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
3.7 kB
1
Indexable
Never
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>

void init(int N, int L, int mAbility[]);
int move();
int trade();

#define MAX_N 39990

#define CMD_INIT 100
#define CMD_MOVE 200
#define CMD_TRADE 300

static bool run()
{
    int query_num;
    scanf("%d", &query_num);

    int ans;
    bool ok = false;

    for (int q = 0; q < query_num; q++)
    {
        int query;
        scanf("%d", &query);
        if (query == CMD_INIT)
        {
            int N;
            int L;
            int mAbility[MAX_N];
            scanf("%d %d", &N, &L);
            for (int i = 0; i < N; i++){
                scanf("%d", &mAbility[i]);
            }
            init(N, L, mAbility);
            ok = true;
        }
        else if (query == CMD_MOVE)
        {
            int ret = move();
            scanf("%d", &ans);
            if (ans != ret)
            {
                ok = false;
            }
        }
        else if (query == CMD_TRADE)
        {
            int ret = trade();
            scanf("%d", &ans);
            if (ans != ret)
            {
                ok = false;
            }
        }
    }
    return ok;
}

int main()
{
    setbuf(stdout, NULL);
    freopen("sample_input.txt", "r", stdin);
    int T, MARK;
    scanf("%d %d", &T, &MARK);

    for (int tc = 1; tc <= T; tc++)
    {
        int score = run() ? MARK : 0;
        printf("#%d %d\n", tc, score);
    }
    return 0;
}
------------------------------------------
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N,L,Width;
struct Node{
    int ID;
    int Ability;
    Node(){};
    Node(int mID,int mAbi){
        ID = mID;
        Ability = mAbi;
    }
};
bool cmp(Node a,Node b){
    if(a.Ability == b.Ability)
        return a.ID < b.ID;
    return a.Ability > b.Ability;
}
vector<Node> League[10];
int findIndex(int mLeague,Node v){
    int low = 0,high = League[mLeague].size()-1,mid;
    while(low != high){
        mid = (low + high)/2;
        if(cmp(League[mLeague][mid],v)){
            low =mid+1;
        }else high=mid;
    }
    return low;
}
void ADD(int mLeague,Node v){
    int Pos = findIndex(mLeague,v);
    if(cmp(League[mLeague][Pos],v)) League[mLeague].insert(League[mLeague].begin()+Pos+1,v);
    else League[mLeague].insert(League[mLeague].begin()+Pos,v);
}
 
void init(int N, int L, int mAbility[])
{
    ::N = N;
    ::L = L;
    Width = N/L;
    for(int i=0;i<L;i++) League[i].clear();
    for(int i=0;i<N;i++) League[i/Width].push_back(Node(i,mAbility[i]));
    for(int i=0;i<L;i++) sort(League[i].begin(),League[i].end(),cmp);
}
int move()
{
    int Ret = 0;
    Node Up,Down,Temp;
    Down = League[0].back();
    League[0].pop_back();
    for(int i=1;i<L;i++){
        Up = League[i].front();
        Temp = League[i].back();
        if(i!= L-1) League[i].pop_back();
        Ret += (Up.ID + Down.ID);
        League[i].erase(League[i].begin());
        ADD(i-1,Up);
        ADD(i,Down);
        Down = Temp;
    }
    return Ret;
}
int trade()
{
    int Ret = 0;
    Node Up,Down,Temp;
    Down = League[0][Width/2];
    League[0].erase(League[0].begin()+Width/2);
    for(int i=1;i<L;i++){
        Up = League[i].front();
        Temp = League[i][Width/2];
        if(i!= L-1) League[i].erase(League[i].begin()+Width/2);
        Ret += (Up.ID + Down.ID);
        League[i].erase(League[i].begin());
        ADD(i-1,Up);
        ADD(i,Down);
        Down = Temp;
    }
    return Ret;
}
----------------------