Ly与lyon的巅峰对决,描色法

http://paste.ubuntu.com/14124956/

#include <stdio.h>
#include <stdlib.h>
struct node
{
    int step;
    int who;
}e[1002][1002];
int next[4][2]={{0,1},{1,0},{1,1},{1,-1}};
int s[6];
int min=9999999;
int n,m;
int max_step()
{
    int i;
    int max=s[1];
    for (i=2;i<=5;i++)
    {
        if (max<s[i])
        {
            max=s[i];
        }
    }
    return max;
}
void did(int i,int j,int m)
{
    int sum=0;
    int tx,ty;
    sum += e[i][j].who;
    tx=i;
    ty=j;
    int k;
    s[1]=e[i][j].step;
    for (k=2;k<=5;k++)
    {
        tx = tx+next[m][0];
        ty = ty+next[m][1];
        if (tx<1||tx>n||ty<1||ty>n||e[tx][ty].who==0) 
        {
            break;
        }
        sum += e[tx][ty].who;
        s[k]=e[tx][ty].step;
    }
    if (sum==-5||sum==5)
    {
        int t=max_step();
        if (min>t)
        {
            min = t;
        }
    }
    return ;
}
int iswin()
{
    int i,j;
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
        {
            if (e[i][j].who!=0)
            {
                did(i,j,0);
                did(i,j,1);
                did(i,j,2);
                did(i,j,3);
            }
        }
    }
    if (min==9999999)
    {
        return 0;
    }
    else 
    {
        return 1;
    }
}
void work()
{
    scanf ("%d%d",&n,&m);
    int i;
    int step=1;
    int j;
    for (i=1;i<=m;i++)
    {
        int x,y;
        scanf ("%d%d",&x,&y);
        if (i%2==0)
        {
            e[x][y].who = -1;
            e[x][y].step = step++;
        }
        else
        {
            e[x][y].who = 1;
            e[x][y].step = step++;
        }
    }
    if (n<5)
    {
        printf ("baga\n");
        return ;
    }
    /*
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
        {
            printf ("%3d ",e[i][j].who);
        }
        printf ("\n");
    }*/
    if (iswin())
    {
        printf ("%d\n",min);
    }
    else 
    {
       printf ("baga\n");
    }
    return ;
}
int main()
{
    work();
    return 0;
}

题目数据应该比较水,30ms过了,如果n=1000而且m=n*n;本人觉得可能会爆   TLE

posted on 2015-12-21 12:24  stupid_one  阅读(276)  评论(0编辑  收藏  举报

导航