ime imited exceeded-uva 220 一直Time Limited exceeded!!!

问题描述

uva 220 一直Time Limited exceeded!!!

不知道为什么在网站上就是Time Limited exceeded,样例测试都没有问题,能不能帮忙看看是什么问题?
#include
#include
#include
using namespace std;
#define maxsize 10
char board[maxsize][maxsize];
int cnt[130]={0};
int ki[8]={-1,-1,-1,0,0,1,1,1};
int kj[8]={-1,0,1,-1,1,-1,0,1};
int fir=1,x,y;

void get_board()
{
memset(board,0,sizeof board);
memset(cnt,0,sizeof cnt);
for(int i=1;i<=8;i++)
{
for(int j=1;j<=8;j++)
{
cin>>board[i][j];
cnt[board[i][j]]++;
}
char ch=getchar();
}
}

void is_legal(char &cur,char &next,int flag)
{
int first=1;

for(int i=1;i<=8;i++)
   for(int j=1;j<=8;j++)
      {
        if(board[i][j]=='-')
        {
          for(int l=0;l<8;l++)
           {
            for(int k=1;;k++)
            {
                if(board[i+k*ki[l]][j+k*kj[l]]==next)
                continue;
                if(board[i+k*ki[l]][j+k*kj[l]]==cur&&k!=1)
                 {
                     if(!flag)
                     {
                     if(first)
                     first=0;
                     else cout<<" ";
                     cout<<"("<<i<<","<<j<<")";
                     }
                     else
                     {
                        if(i==x&&j==y)
                        {

                            for(int t=0;t<k;t++)
                            board[i+t*ki[l]][j+t*kj[l]]=cur;
                            cnt[cur]+=k;
                            cnt[next]-=k-1;
                            cout<<"Black - "<<cnt['B']<<" White - "<<cnt['W']<<endl;
                            return ;
                        }

                     }
                   }
                 else break;
            }
        }
      }
      }
     if(!flag)
     {
        if(first)
        cout<<"No legal move.";
        cout<<endl;
     }
     else
     {
        swap(next,cur);
        is_legal(cur,next,flag);
     }

}

void LM(char &cur,int flag)
{
char next;
if(cur=='B')
next='W';
else next='B';
if(flag)

{
int a;
cin>>a;
x=a/10;
y=a%10;
}
is_legal(cur,next,flag);
if(flag)
swap(cur,next);
}

void Quit()
{
for(int i=1;i<=8;i++)
{
for(int j=1;j<=8;j++)
{
cout<<board[i][j];
}
cout<<endl;
}
}

int main()
{
int t;
scanf("%d",&t);
while(t--)
{
if(fir)
fir=0;
else cout<<endl;
while(getchar()!='n');

    get_board();
    char cur=getchar();
    char cmd;
    for(;;)
    {
        cmd=getchar();
        cmd=getchar();
        switch(cmd)
        {
            case'L':LM(cur,0);
                    break;
            case'M':LM(cur,1);
                    break;

            case'Q':Quit();
                    break;
        }
        if(cmd=='Q')
        break;
    }
}
return 0;

}


时间: 2024-09-29 20:33:39

ime imited exceeded-uva 220 一直Time Limited exceeded!!!的相关文章

UVA之11078 - Open Credit System

[题目] Problem E Open Credit System Input: Standard Input Output: Standard Output In an open credit system, the students can choose any course they like, but there is a problem. Some of the students are more senior than other students. The professor of

TNS-12540: TNS:internal limit restriction exceeded

   应用程序以及客户端工具(Toad.PL/SQL Developer等)出现突然连接不上数据库服务器的情况,监听日志listener.log里面出现了TSN-12518与TSN-12540错误,如下所示, 27-JAN-2015 10:10:19 * (CONNECT_DATA=(SERVICE_NAME=scm2)(CID=(PROGRAM=c:\windows\system32\inetsrv\w3wp.exe)(HOST=POS)(USER=SYSTEM))) * (ADDRESS=(

Linux中Kill进程的N种方法

常规篇: 首先,用ps查看进程,方法如下: $ ps -ef -- smx       1822     1  0 11:38 ?        00:00:49 gnome-terminal smx       1823  1822  0 11:38 ?        00:00:00 gnome-pty-helper smx       1824  1822  0 11:38 pts/0    00:00:02 bash smx       1827     1  4 11:38 ?    

Linux系统Kill进程的N种方法

首先,用ps查看进程,方法如下: $ ps -ef -- smx       1822     1  0 11:38 ?        00:00:49 gnome-terminal smx       1823  1822  0 11:38 ?        00:00:00 gnome-pty-helper smx       1824  1822  0 11:38 pts/0    00:00:02 bash smx       1827     1  4 11:38 ?        0

I.MX6 U-Boot ping网络

/********************************************************************* * I.MX6 U-Boot ping网络 * 说明: * 百兆网络是可以,千兆网络数据发送不出去,看一下U-Boot千兆网络是否 * 正常,问题同样存在. * * 2017-4-12 深圳 龙华民治樟坑村 曾剑锋 ********************************************************************/ 操

UVa 350 Pseudo-Random Numbers:伪随机数的循环长度

350 - Pseudo-Random Numbers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=286 Computers normally cannot generate really random numbers, but frequently

UVa 165:Stamps, 连续邮资问题

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108 类型: 回溯 原题: The government of Nova Mareterrania requires that various legal documents have stamps attached to them so that the government can derive revenue fro

UVa 514 Rails (water ver.)

514 - Rails Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=455 There is a famous railway station in PopPush City. Country there is incredibly hilly. The

UVa 327 Evaluating Simple C Expressions (模拟)

327 - Evaluating Simple C Expressions Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=104&page=show_problem&problem=263 The task in this problem is to evaluate a sequence of simple C