比赛 20120704 评测结果 AAAAAAAAAA
题目名称 椰子 最终得分 100
用户昵称 Citron酱 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2012-07-04 09:08:02
显示代码纯文本
#include <cstdio>
 
#define I_F "coconuts.in"
#define O_F "coconuts.out"
 
const int MAXn=1000;
const int Yl=3000;
const int Yf=1000;
const short MAXx=32;
 
struct coconut
{
    int w, x, y;
};
 
int map[Yl][MAXx+1];
coconut s[MAXn];
int n;
 
void Input();
void Clear();
void Fall(const int, const int);
void Search();
void Output();
 
int main()
{
    freopen(I_F,"r",stdin);
    freopen(O_F,"w",stdout);
    int t;
    for (scanf("%d",&t); t>0; --t)
    {
        Input();
        Clear();
        Search();
        Output();
    }
    return 0;
}
 
void Input()
{
    scanf("%d",&n);
    for (int i=0; i<n; ++i)
        scanf("%d%d",&s[i].y,&s[i].w);
}
 
void Clear()
{
    for (int i=0; i<Yl; ++i)
    {
        map[i][0]=-1;
        for (int j=1; j<=MAXx; ++j)
            map[i][j]=-2;
    }
}
 
void Fall(const int y, const int x)
{
    if (map[y+Yf][x-1]==-2)
    {
        map[y+Yf][x-1]=map[y+Yf][x];
        map[y+Yf][x]=-2;
        --s[map[y+Yf][x-1]].x;
        Fall(y,x-1);
    }
    else
        if (map[y-1+Yf][x-1]==-2)
            if (map[y+1+Yf][x-1]==-2)
                if (s[map[y+Yf][x]].w>s[map[y+Yf][x-1]].w)
                {
                    map[y+1+Yf][x-1]=map[y+Yf][x-1];
                    map[y+Yf][x-1]=map[y+Yf][x];
                    map[y+Yf][x]=-2;
                    ++s[map[y+1+Yf][x-1]].y;
                    --s[map[y+Yf][x-1]].x;
                    Fall(y+1,x-1);
                }
                else
                {
                    map[y-1+Yf][x-1]=map[y+Yf][x];
                    map[y+Yf][x]=-2;
                    --s[map[y-1+Yf][x-1]].x;
                    --s[map[y-1+Yf][x-1]].y;
                    Fall(y-1,x-1);
                }
            else
                if (s[map[y+Yf][x]].w>s[map[y+Yf][x-1]].w)
                {
                    map[y-1+Yf][x-1]=map[y+Yf][x-1];
                    map[y+Yf][x-1]=map[y+Yf][x];
                    map[y+Yf][x]=-2;
                    --s[map[y-1+Yf][x-1]].y;
                    --s[map[y+Yf][x-1]].x;
                    Fall(y-1,x-1);
                }
                else
                {
                    map[y-1+Yf][x-1]=map[y+Yf][x];
                    map[y+Yf][x]=-2;
                    --s[map[y-1+Yf][x-1]].x;
                    --s[map[y-1+Yf][x-1]].y;
                    Fall(y-1,x-1);
                }
        else
            if (map[y+1+Yf][x-1]==-2)
                if (s[map[y+Yf][x]].w>s[map[y+Yf][x-1]].w)
                {
                    map[y+1+Yf][x-1]=map[y+Yf][x-1];
                    map[y+Yf][x-1]=map[y+Yf][x];
                    map[y+Yf][x]=-2;
                    ++s[map[y+1+Yf][x-1]].y;
                    --s[map[y+Yf][x-1]].x;
                    Fall(y+1,x-1);
                }
                else
                {
                    map[y+1+Yf][x-1]=map[y+Yf][x];
                    map[y+Yf][x]=-2;
                    --s[map[y+1+Yf][x-1]].x;
                    ++s[map[y+1+Yf][x-1]].y;
                    Fall(y+1,x-1);
                }
            else
                return;
}
 
void Search()
{
    for (int i=0; i<n; ++i)
    {
        s[i].x=MAXx;
        map[s[i].y+Yf][s[i].x]=i;
        Fall(s[i].y,s[i].x);
    }
}
 
void Output()
{
    for (int i=0; i<n; ++i)
        printf("%d %d\n",s[i].x,s[i].y);
    printf("\n");
}