/* ID:xiekeyi1 PROG:transform LANG:C++ */ #include<bits/stdc++.h> usingnamespacestd ; //#define DEBUG constint maxn = 15 ; char a[maxn][maxn] , b[maxn][maxn] , c[maxn][maxn]; //template<typename T> //void swap( T &a , T &b ) //{ // T c ; // c = a ; // a = b ; // b = a ; // return ; //}
booljudge( char a[maxn][maxn] , char b[maxn][maxn] , int &n ) { for( int i = 1 ; i <= n ; i++) for( int j = 1 ; j <= n ; j++) if( a[i][j] != b[i][j] ) returnfalse ; returntrue ; }
introlate( int &n ) { for( int i = 1 ; i <= n ; i++) { for( int j = 1 ; j <= n ; j++) { c[j][n-i+1] = a[i][j] ; } } if( judge( c , b , n ) ) return1 ;
for( int i = 1 ; i <= n ; i++) { for( int j = 1 ; j <= n ; j++) { c[n-i+1][n-j+1] = a[i][j] ; } } if( judge ( c , b , n ) ) return2;
for( int i = 1 ; i <= n ; i++) { for( int j = 1 ; j <= n ; j++) { c[n-j+1][i] = a[i][j] ; } }
if( judge ( c , b , n ) ) return3 ; for( int i = 1 ; i <= n ; i++) for( int j = 1 ; j <= n ; j++) c[i][j] = a[i][j] ; for( int i = 1 ; i <= n ; i++) { for( int j = 1 ; j <= n / 2 ; j++) { swap( c[i][j] , c[i][n-j+1]) ; } } if( judge( c , b , n ) ) return4 ;
// for( int i = 1 ; i <= n ; i++) // for( int j = 1 ; j <=n ; j++) // c[i][j] = a[i][j] ; #ifdef DEBUG for( int i = 1 ; i <= n ; i++) { for( int j = 1 ; j <= n ; j++) cout << c[i][j]; cout << endl ; } cout << endl << endl ; #endif char d[maxn][maxn]; for( int i = 1 ; i <= n ; i++) for( int j = 1 ; j <= n ; j++) d[j][n-i+1] = c[i][j] ; #ifdef DEBUG for( int i = 1 ; i <= n ; i++) { for( int j = 1 ; j <= n ; j++) cout << d[i][j] ; cout << endl ; } cout << endl << endl ; #endif if( judge( d , b , n ) ) return5 ; for( int i = 1 ; i <= n ; i++) for( int j = 1 ; j <= n ; j++) d[n-i+1][n-j+1] = c[i][j] ; #ifdef DEBUG for( int i = 1 ; i <= n ; i++) { for( int j = 1 ; j <= n ; j++) cout << d[i][j] ; cout << endl ; } cout << endl << endl ; #endif if( judge( d , b , n ) ) return5 ; for( int i = 1 ; i <= n ; i++) for( int j = 1 ; j <= n ; j++) d[n-j+1][i] = a[i][j] ; #ifdef DEBUG for( int i = 1 ; i <= n ; i++) { for( int j = 1 ; j <= n ; j++) cout << d[i][j] ; cout << endl ; } cout << endl << endl ; #endif if( judge( d , b , n ) ) return5 ;
if( judge( a , b , n ) ) return6 ;
return7 ;
}
intmain() { freopen("transform.in","r",stdin); freopen("transform.out","w",stdout) ; int n ; cin >> n ; char ch ; for( int i = 1 ; i <= n ; i++) for( int j = 1 ; j <=n ; j++) { cin >> ch ; a[i][j] = ch ; }
for( int i = 1 ; i <= n ; i++ ) for( int j = 1 ; j <= n ; j++) { cin >> ch ; b[i][j] = ch ; }
voidtranslate( int n , int B , int flag , int &d ) { int digit = 0 ; while( n != 0 ) { if( flag == 1 ) a[digit++] = n % B ; else b[digit++] = n % B ; n /= B ; } d = digit ; return ;
}
booljudge( int b[] , int d ) { for( int i = 0 ; i <= d / 2 ; i++) if( b[i] != b[d-i-1] ) returnfalse ; returntrue ; }
ostream& p( int b[] , int d ) { for( int i = d - 1 ; i >= 0 ; i--) { if( b[i] < 10 ) cout << b[i] ; else cout << static_cast<char> ( b[i] - 10 + 'A' ) ; } returncout ; }
intmain() { freopen("palsquare.in","r",stdin); freopen("palsquare.out","w",stdout); int B ; cin >> B ; for( int i = 1 ; i <= 300 ; i++) { int d1 = 0 , d2 = 0 ; int t = i * i ; translate( t , B , 2 , d2 ) ; if( judge( b , d2 ) ) { translate( i , B , 1 , d1 ) ; p(a,d1) << ' ' ; p(b,d2) << endl ;
voidf( int a[] , int n , int b , int &d ) { int digit = 0 ; while( n != 0 ) { a[digit++] = n % b ; n /= b ; } d = digit ; return ; }
booljudge( int a[] , int d ) { for( int i = 0 ; i <= d/2 ; i++) if( a[i] != a[ d-i-1] ) returnfalse ; returntrue ; } intmain() {
freopen("dualpal.in","r",stdin); freopen("dualpal.out","w",stdout); int n , s ; cin >> n >> s ; int i = 0 ; int temp = s+1 ; for( i = 0 ; i < n ; ) { int flag = 0 ; for( int j = 2 ; j <= 10 ; j++) { int d = 0 ; f(a,temp,j,d); if( judge( a , d ) ) flag++; if( flag >= 2 ) { cout << temp << endl ; i++; break ; } } temp++; } return0 ; }