其他分享
首页 > 其他分享> > CF1450C2 Errich-Tac-Toe

CF1450C2 Errich-Tac-Toe

作者:互联网

#include <cstdio>
#include <cstring>

const int MAXN = 300;
int T , n , k , cnt; char str[ MAXN + 5 ][ MAXN + 5 ] , Ans[ MAXN + 5 ][ MAXN + 5 ];

int main( ) {
	scanf("%d",&T);
	while( T -- ) {
		scanf("%d",&n); k = 0;
		for( int i = 1 ; i <= n ; i ++ ) scanf("%s", str[ i ] + 1 );
		for( int i = 1 ; i <= n ; i ++ ) for( int j = 1 ; j <= n ; j ++ ) k += str[ i ][ j ] != '.';
		
		cnt = 0; memcpy( Ans , str , sizeof( str ) ); 
		for( int i = 1 ; i <= n ; i ++ )
			for( int j = 1 ; j <= n ; j ++ ) if( str[ i ][ j ] != '.' ) {
				if( ( i + j ) % 3 == 0 ) Ans[ i ][ j ] = 'X' , cnt += Ans[ i ][ j ] != str[ i ][ j ];
				if( ( i + j ) % 3 == 1 ) Ans[ i ][ j ] = 'O' , cnt += Ans[ i ][ j ] != str[ i ][ j ];
			}
		if( cnt <= k / 3 ) {
			for( int i = 1 ; i <= n ; i ++ ) puts( Ans[ i ] + 1 );
			continue;
		}
		
		cnt = 0; memcpy( Ans , str , sizeof( str ) ); 
		for( int i = 1 ; i <= n ; i ++ )
			for( int j = 1 ; j <= n ; j ++ ) if( str[ i ][ j ] != '.' ) {
				if( ( i + j ) % 3 == 1 ) Ans[ i ][ j ] = 'X' , cnt += Ans[ i ][ j ] != str[ i ][ j ];
				if( ( i + j ) % 3 == 2 ) Ans[ i ][ j ] = 'O' , cnt += Ans[ i ][ j ] != str[ i ][ j ];
			}
		if( cnt <= k / 3 ) {
			for( int i = 1 ; i <= n ; i ++ ) puts( Ans[ i ] + 1 );
			continue;
		}
		
		cnt = 0; memcpy( Ans , str , sizeof( str ) ); 
		for( int i = 1 ; i <= n ; i ++ )
			for( int j = 1 ; j <= n ; j ++ ) if( str[ i ][ j ] != '.' ) {
				if( ( i + j ) % 3 == 2 ) Ans[ i ][ j ] = 'X' , cnt += Ans[ i ][ j ] != str[ i ][ j ];
				if( ( i + j ) % 3 == 0 ) Ans[ i ][ j ] = 'O' , cnt += Ans[ i ][ j ] != str[ i ][ j ];
			}
		if( cnt <= k / 3 ) {
			for( int i = 1 ; i <= n ; i ++ ) puts( Ans[ i ] + 1 );
			continue;
		}
	}
	return 0;
}

标签:char,cnt,int,scanf,CF1450C2,MAXN,include,Errich,Toe
来源: https://www.cnblogs.com/chihik/p/CF1450C.html