Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

TLE 改了无数次还是不对,求解释

Posted by 2857 at 2012-08-27 09:34:18 on Problem 1728
Code :

#include <stdio.h>

int vis[1010][1010];
long long s,tx,ty;

void turn(long long x,long long y)
{
    tx=x%(2*s);
    ty=y%(2*s);
         if(tx>s&&ty>s)     tx-=s,ty-=s;
    else if(tx>s&&ty%s==0)  tx-=s;
    else if(tx%s==0&&ty>s)  ty-=s;
}

int main()
{
    long long x,y,dx,dy,con,flag;
    while(scanf("%I64d %I64d %I64d %I64d %I64d",&s,&x,&y,&dx,&dy))
    {
       if(s+x+y+dx+dy==0)  break;
       con=0;
       memset(vis,0,sizeof(vis));
       
       do
       {
          turn(x,y);
          if(tx>s||ty>s)   {flag=1;break;}
          if(vis[tx][ty])  {flag=0;break;}
          vis[tx][ty]=1;
          x+=dx,y+=dy;
       }while(++con);
       
       if(flag)  printf("After %I64d jumps the flea lands at (%I64d, %I64d).\n",con,x,y);
       else      printf("The flea cannot escape from black squares.\n");
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator