现在的位置: 首页 > 综合 > 正文

[U]Cow Tours

2014年09月05日 ⁄ 综合 ⁄ 共 724字 ⁄ 字号 评论关闭

简单的模拟题,如果是要找周期性的话,真不会啊~....

/*
ID:sevenst4
LANG:C++
PROG:ttwo
*/
#include<stdio.h>
using namespace std;

char map[20][20];
void rotate( int &x,int &y )
{
 	 int tx,ty;
 	 tx=x;ty=y;
 	 x=ty;
 	 y=-tx;
}

int main()
{
 	freopen( "ttwo.in","r",stdin );
 	freopen( "ttwo.out","w",stdout );
 	int xf,yf,xc,yc;
 	for( int i=1;i<=10;i++ )
 	{
  	 	 scanf( "%s",map[i]+1 );
 		 for( int j=1;j<=10;j++ )
		 {
	 	  	  if( map[i][j]=='F' ){
		  	  	  xf=i,yf=j;
	          }
		 	  if( map[i][j]=='C' ){
		  	  	  xc=i,yc=j;
  		      }
  		 }
	}
	
 	for( int i=0;i<12;i++ )
 		 map[0][i]=map[i][0]=map[11][i]=map[i][11]='*';
 
    int step=0;
    int cx,cy,fx,fy;
    cx=fx=-1;
    cy=fy=0;
    while( step<1000000 )
    {
	 	   if( map[xc+cx][yc+cy]=='*' )
  	   	   {   rotate(cx,cy); }
		   else
		   {   xc+=cx;yc+=cy;	}
		   if( map[xf+fx][yf+fy]=='*' )
		   {   rotate(fx,fy); }
		   else
		   {   xf+=fx;yf+=fy; }
		   step++;
		   if( xc==xf && yc==yf )
		   	   break;
    }
    if( step<1000000 )
    	printf( "%d\n",step );
    else
    	printf( "0\n" );
    return 0;
}
【上篇】
【下篇】

抱歉!评论已关闭.