| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Wa的有点郁闷了。。。谁有时间帮忙看看吧。。。#include<iostream> using namespace std; #define N 1005 struct node{ int flag , id ; node * ptr [ 26 ] ; }table[ N * 503 ]; int indexx; int out[N][3],di[8][2] = { {-1 , 0 },{ -1 , 1 },{0 , 1},{1,1},{1, 0},{1 , -1 },{0,-1},{-1,-1} }; char map[N][N] , rel[N][20]; int yes[N], per[N]; int main() { int i , j , k , n , m , x , y , l ; int L , C , W ; memset ( yes , 0 , sizeof ( yes )); scanf("%d%d%d",&L,&C,&W); for ( i = 0 ; i < L ; i ++ ) { scanf("%s",map[i] ); } for ( i = 0 ; i < W ; i ++ ) scanf("%s",rel[i]); node * head ,* p; indexx = 0 ; table[indexx].flag = 0; table[indexx].id= -1; for ( k = 0 ; k < 26 ; k ++ ) table[indexx].ptr[k] = 0; head = & table [ indexx ++ ] ; int maxx = 20; int cnt = 0; char c; for ( i = 0 ; i < W ; i ++ ) { l = strlen( rel [i]); maxx = maxx > l ? maxx : l; p = head ; for ( j= 0 ;j < l ; j ++ ) { if ( p -> ptr[ rel[i][j] - 'A' ] == 0 ) { table[indexx].flag = 0; table[indexx].id = -1 ; for ( k = 0 ; k < 26 ; k ++ ) table[indexx].ptr[k] = 0; p -> ptr[ rel [i][j] - 'A' ] = & table [ indexx ++ ] ; } p = p -> ptr[ rel [i][j] - 'A' ] ; } p -> flag = 1 ; p -> id = i ; } for ( i = 0 ; i < W ; i ++ ) { l = strlen ( rel[i] ); p = head; for ( j = 0 ; j < l ; j ++ ) { c = rel [i][j] ; if ( p -> ptr[ c - 'A' ] == 0 ) { table [ indexx ].id = -1 ; p -> ptr[ c - 'A' ] = & table[ indexx ++ ]; } p = p -> ptr [ c - 'A' ] ; } p -> id = i ; p -> flag = 1 ; } for ( i = 0 ; i < L ; i ++ ) { for ( j = 0 ; j < C ; j ++ ) { for ( k = 0 ; k < 8 ; k ++ ) { x = i ; y = j ; p = head ; for ( l = 0 ; l < maxx + 3 ; l ++ ) { if( !(x >= 0 && x < L && y >= 0 && y < C) ) break; c = map[ x ] [ y ]; if ( p -> ptr[ c - 'A' ] == 0 ) break; p = p -> ptr[ c - 'A' ] ; if ( p -> id > -1 ) { out [ p -> id ] [ 0 ] = i ; out [ p -> id ] [ 1 ] = j ; out [ p -> id ] [ 2 ] = k ; yes [ p -> id ] = 1; } x += di[k][0]; y += di[k][1]; } } } } for ( i = 0 ; i < W ;i ++ ) { printf("%d %d %c\n",out[i][0],out[i][1],out[i][2] + 'A' ); } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator