# CF1205C Palindromic Paths

### 问题分析

printf( "? 1 1 2 3\n" ); fflush( stdout );
int x; scanf( "%d", &x );
if( x == 1 && A[ 1 ][ 1 ] != A[ 2 ][ 3 ] )
for( int i = 1; i <= n; ++i )
for( int j = 1; j <= n; ++j )
if( ( i + j ) % 2 )
A[ i ][ j ] = ( A[ i ][ j ] == 1 ) ? 0 : 1;
if( x == 0 && A[ 1 ][ 1 ] == A[ 2 ][ 3 ] &&
( A[ 2 ][ 1 ] == A[ 2 ][ 2 ] || A[ 1 ][ 2 ] == A[ 2 ][ 2 ] || A[ 1 ][ 2 ] == A[ 1 ][ 3 ] ) )
for( int i = 1; i <= n; ++i )
for( int j = 1; j <= n; ++ j )
if( ( i + j ) % 2 )
A[ i ][ j ] = ( A[ i ][ j ] == 1 ) ? 0 : 1;


110
101
110


### 参考程序

#include <bits/stdc++.h>
using namespace std;

const int Maxn = 60;
int n, A[ Maxn ][ Maxn ], x;

int Check( int x1, int y1, int x2, int y2 ) {
if( x1 == x2 ) return 1 ^ A[ x1 ][ y1 ] ^ A[ x1 ][ y1 + 1 ] ^ A[ x1 ][ y1 + 2 ] ^ A[ x1 ][ y2 ];
if( x1 + 1 == x2 ) {
int t = A[ x1 ][ y1 ] ^ A[ x2 ][ y2 ];
return ( t == ( A[ x1 + 1 ][ y1 ] ^ A[ x1 + 1 ][ y1 + 1 ] ) ) ||
( t == ( A[ x1 ][ y1 + 1 ] ^ A[ x1 + 1 ][ y1 + 1 ] ) ) ||
( t == ( A[ x1 ][ y1 + 1 ] ^ A[ x1 ][ y1 + 2 ] ) );
}
if( x1 + 2 == x2 ) {
int t = A[ x1 ][ y1 ] ^ A[ x2 ][ y2 ];
return ( t == ( A[ x1 + 1 ][ y1 ] ^ A[ x1 + 2 ][ y1 ] ) ) ||
( t == ( A[ x1 + 1 ][ y1 ] ^ A[ x1 + 1 ][ y1 + 1 ] ) ) ||
( t == ( A[ x1 ][ y1 + 1 ] ^ A[ x1 + 1 ][ y1 + 1 ] ) );
}
if( x1 + 3 == x2 ) return 1 ^ A[ x1 ][ y1 ] ^ A[ x1 + 1 ][ y1 ] ^ A[ x1 + 2 ][ y1 ] ^ A[ x2 ][ y1 ];
return 0;
}

void Swap() {
for( int i = 1; i <= n; ++i )
for( int j = 1; j <= n; ++j )
if( ( i + j ) % 2 )
A[ i ][ j ] = ( A[ i ][ j ] == 1 ) ? 0 : 1;
return;
}

void Trans() {
for( int i = 1; i <= n; ++i )
for( int j = 1; j <= n; ++j )
for( int k = 0; k < 4; ++k )
if( i + k <= n && j + 3 - k <= n && Check( i, j, i + k, j + 3 - k ) ) {
printf( "? %d %d %d %d\n", i, j, i + k, j + 3 - k ); fflush( stdout ); scanf( "%d", &x );
if( x == 1 && A[ i ][ j ] != A[ i + k ][ j + 3 - k ] ) Swap();
if( x == 0 && A[ i ][ j ] == A[ i + k ][ j + 3 - k ] ) Swap();
return;
}
return;
}

int main() {
memset( A, 0, sizeof( A ) );
A[ 1 ][ 1 ] = 1;
scanf( "%d", &n );
for( int i = 1; i <= n; ++i )
for( int j = 1; j <= n; ++j ) {
if( i == 2 && j == 1 ) {
printf( "? 2 1 2 3\n" ); fflush( stdout ); scanf( "%d", &x );
if( x == 0 ) A[ 2 ][ 1 ] = ( A[ 2 ][ 3 ] == 1 ) ? 0 : 1;
if( x == 1 ) A[ 2 ][ 1 ] = ( A[ 2 ][ 3 ] == 1 ) ? 1 : 0;
}
if( i == 1 && j + 2 <= n ) {
printf( "? %d %d %d %d\n", i, j, i, j + 2 ); fflush( stdout ); scanf( "%d", &x );
if( x == 0 ) A[ i ][ j + 2 ] = ( A[ i ][ j ] == 1 ) ? 0 : 1;
if( x == 1 ) A[ i ][ j + 2 ] = ( A[ i ][ j ] == 1 ) ? 1 : 0;
}
if( j == 1 && i + 2 <= n ) {
printf( "? %d %d %d %d\n", i, j, i + 2, j ); fflush( stdout ); scanf( "%d", &x );
if( x == 0 ) A[ i + 2 ][ j ] = ( A[ i ][ j ] == 1 ) ? 0 : 1;
if( x == 1 ) A[ i + 2 ][ j ] = ( A[ i ][ j ] == 1 ) ? 1 : 0;
}
if( i + 1 <= n && j + 1 <= n && i + j + 2 < n + n ) {
printf( "? %d %d %d %d\n", i, j, i + 1, j + 1 ); fflush( stdout ); scanf( "%d", &x );
if( x == 0 ) A[ i + 1 ][ j + 1 ] = ( A[ i ][ j ] == 1 ) ? 0 : 1;
if( x == 1 ) A[ i + 1 ][ j + 1 ] = ( A[ i ][ j ] == 1 ) ? 1 : 0;
}
}
Trans();
printf( "!\n" ); fflush( stdout );
for( int i = 1; i <= n; ++i ) {
for( int j = 1; j <= n; ++j )
printf( "%d", A[ i ][ j ] ), fflush( stdout );
printf( "\n" ); fflush( stdout );
}
return 0;
}

posted @ 2019-09-07 13:37  chy_2003  阅读(172)  评论(0编辑  收藏