不知道为什么感觉1.2比1.1反而简单不少
1 /* 2 ID:xiekeyi1 3 PROG:milk2 4 LANG:C++ 5 */ 6 #include<bits/stdc++.h> 7 using namespace std ; 8 const int MAXN = 5010; 9 struct point 10 { 11 int begin , end ; 12 } a[MAXN] ; 13 14 15 bool cmp( struct point a , struct point b ) 16 { 17 if( a.begin < b.begin) 18 return true ; 19 else if( a.begin == b.begin && a.end < b.end ) 20 return true ; 21 else 22 return false ; 23 } 24 int main() 25 { 26 freopen("milk2.in","r",stdin); 27 freopen("milk2.out","w",stdout); 28 29 int n ; 30 cin >> n ; 31 for( int i = 1 ; i <= n ; i++) 32 cin >> a[i].begin >> a[i].end ; 33 sort(a+1,a+1+n,cmp) ; 34 int ans1= 0 , ans2 = 0 ; 35 int tem_begin = a[1].begin , tem_end= a[1].end; 36 ans1 = max( tem_end - tem_begin , ans1 ); 37 for( int i = 2 ; i <=n ; i++) 38 { 39 if( a[i].begin <= tem_end) 40 { 41 tem_end = max( tem_end , a[i].end) ; 42 } 43 else 44 { 45 ans1 = max(ans1 , tem_end - tem_begin ) ; 46 ans2 =max( ans2 , a[i].begin - tem_end) ; 47 48 tem_begin = a[i].begin; 49 tem_end = a[i].end ; 50 } 51 } 52 53 cout << ans1 << ‘ ‘ << ans2 << endl ; 54 return 0 ; 55 }
Milking Cows
1 /* 2 ID:xiekeyi1 3 PROG:transform 4 LANG:C++ 5 */ 6 #include<bits/stdc++.h> 7 using namespace std ; 8 //#define DEBUG 9 const int maxn = 15 ; 10 char a[maxn][maxn] , b[maxn][maxn] , c[maxn][maxn]; 11 //template<typename T> 12 //void swap( T &a , T &b ) 13 //{ 14 // T c ; 15 // c = a ; 16 // a = b ; 17 // b = a ; 18 // return ; 19 //} 20 21 bool judge( char a[maxn][maxn] , char b[maxn][maxn] , int &n ) 22 { 23 for( int i = 1 ; i <= n ; i++) 24 for( int j = 1 ; j <= n ; j++) 25 if( a[i][j] != b[i][j] ) 26 return false ; 27 return true ; 28 } 29 30 31 int rolate( int &n ) 32 { 33 for( int i = 1 ; i <= n ; i++) 34 { 35 for( int j = 1 ; j <= n ; j++) 36 { 37 c[j][n-i+1] = a[i][j] ; 38 } 39 } 40 if( judge( c , b , n ) ) 41 return 1 ; 42 43 for( int i = 1 ; i <= n ; i++) 44 { 45 for( int j = 1 ; j <= n ; j++) 46 { 47 c[n-i+1][n-j+1] = a[i][j] ; 48 } 49 } 50 if( judge ( c , b , n ) ) 51 return 2; 52 53 for( int i = 1 ; i <= n ; i++) 54 { 55 for( int j = 1 ; j <= n ; j++) 56 { 57 c[n-j+1][i] = a[i][j] ; 58 } 59 } 60 61 if( judge ( c , b , n ) ) 62 return 3 ; 63 for( int i = 1 ; i <= n ; i++) 64 for( int j = 1 ; j <= n ; j++) 65 c[i][j] = a[i][j] ; 66 for( int i = 1 ; i <= n ; i++) 67 { 68 for( int j = 1 ; j <= n / 2 ; j++) 69 { 70 swap( c[i][j] , c[i][n-j+1]) ; 71 } 72 } 73 if( judge( c , b , n ) ) 74 return 4 ; 75 76 // for( int i = 1 ; i <= n ; i++) 77 // for( int j = 1 ; j <=n ; j++) 78 // c[i][j] = a[i][j] ; 79 #ifdef DEBUG 80 for( int i = 1 ; i <= n ; i++) 81 { 82 for( int j = 1 ; j <= n ; j++) 83 cout << c[i][j]; 84 cout << endl ; 85 } 86 cout << endl << endl ; 87 #endif 88 char d[maxn][maxn]; 89 for( int i = 1 ; i <= n ; i++) 90 for( int j = 1 ; j <= n ; j++) 91 d[j][n-i+1] = c[i][j] ; 92 #ifdef DEBUG 93 for( int i = 1 ; i <= n ; i++) 94 { 95 for( int j = 1 ; j <= n ; j++) 96 cout << d[i][j] ; 97 cout << endl ; 98 } 99 cout << endl << endl ; 100 #endif 101 if( judge( d , b , n ) ) 102 return 5 ; 103 for( int i = 1 ; i <= n ; i++) 104 for( int j = 1 ; j <= n ; j++) 105 d[n-i+1][n-j+1] = c[i][j] ; 106 #ifdef DEBUG 107 for( int i = 1 ; i <= n ; i++) 108 { 109 for( int j = 1 ; j <= n ; j++) 110 cout << d[i][j] ; 111 cout << endl ; 112 } 113 cout << endl << endl ; 114 #endif 115 if( judge( d , b , n ) ) 116 return 5 ; 117 for( int i = 1 ; i <= n ; i++) 118 for( int j = 1 ; j <= n ; j++) 119 d[n-j+1][i] = a[i][j] ; 120 #ifdef DEBUG 121 for( int i = 1 ; i <= n ; i++) 122 { 123 for( int j = 1 ; j <= n ; j++) 124 cout << d[i][j] ; 125 cout << endl ; 126 } 127 cout << endl << endl ; 128 #endif 129 if( judge( d , b , n ) ) 130 return 5 ; 131 132 if( judge( a , b , n ) ) 133 return 6 ; 134 135 return 7 ; 136 137 } 138 139 140 141 int main() 142 { 143 freopen("transform.in","r",stdin); 144 freopen("transform.out","w",stdout) ; 145 int n ; 146 cin >> n ; 147 char ch ; 148 for( int i = 1 ; i <= n ; i++) 149 for( int j = 1 ; j <=n ; j++) 150 { 151 cin >> ch ; 152 a[i][j] = ch ; 153 } 154 155 for( int i = 1 ; i <= n ; i++ ) 156 for( int j = 1 ; j <= n ; j++) 157 { 158 cin >> ch ; 159 b[i][j] = ch ; 160 } 161 162 cout << rolate(n) << endl ; 163 return 0 ; 164 }
Transformations
1 /* 2 ID:xiekeyi 3 PROG:namenum 4 LANG:C++ 5 */ 6 #include<bits/stdc++.h> 7 #include<iostream> 8 using namespace std ; 9 10 int f( char ch ) 11 { 12 if( ch < ‘Q‘ ) 13 return ( ch - ‘A‘ + 1 + 2 ) / 3 + 1 ; 14 else 15 return ( ch - ‘A‘ + 1 + 1 ) / 3 + 1 ; 16 17 } 18 19 long long func( string &s) 20 { 21 long long ans = 0 ; 22 for( int i = 0 ; i < s.size() ; i++) 23 ans = ans*10 + f(s[i]) ; 24 return ans ; 25 } 26 27 int main() 28 { 29 ifstream fin ; 30 freopen("namenum.out","w",stdout); 31 fin.open("namenum.in",fstream::in); 32 long long n ; 33 fin >> n ; 34 string s ; 35 fin.close() ; 36 fin.open("dict.txt",fstream::in); 37 bool flag = false ; 38 while( fin >> s ) 39 if( func(s) == n ) 40 { 41 cout << s << endl ; 42 flag = true ; 43 } 44 if( !flag ) 45 cout << "NONE" << endl ; 46 fin.close() ; 47 return 0 ; 48 }
Name That Number
1 /* 2 ID:xiekeyi1 3 PROG:palsquare 4 LANG:C++ 5 */ 6 #include<bits/stdc++.h> 7 using namespace std ; 8 const int maxn = 1000; 9 int a[maxn] , b[maxn] ; 10 11 12 13 void translate( int n , int B , int flag , int &d ) 14 { 15 int digit = 0 ; 16 while( n != 0 ) 17 { 18 if( flag == 1 ) 19 a[digit++] = n % B ; 20 else 21 b[digit++] = n % B ; 22 n /= B ; 23 } 24 d = digit ; 25 return ; 26 27 } 28 29 bool judge( int b[] , int d ) 30 { 31 for( int i = 0 ; i <= d / 2 ; i++) 32 if( b[i] != b[d-i-1] ) 33 return false ; 34 return true ; 35 } 36 37 38 ostream& p( int b[] , int d ) 39 { 40 for( int i = d - 1 ; i >= 0 ; i--) 41 { 42 if( b[i] < 10 ) 43 cout << b[i] ; 44 else 45 cout << static_cast<char> ( b[i] - 10 + ‘A‘ ) ; 46 } 47 return cout ; 48 } 49 50 int main() 51 { 52 freopen("palsquare.in","r",stdin); 53 freopen("palsquare.out","w",stdout); 54 int B ; 55 cin >> B ; 56 for( int i = 1 ; i <= 300 ; i++) 57 { 58 int d1 = 0 , d2 = 0 ; 59 int t = i * i ; 60 translate( t , B , 2 , d2 ) ; 61 if( judge( b , d2 ) ) 62 { 63 translate( i , B , 1 , d1 ) ; 64 p(a,d1) << ‘ ‘ ; 65 p(b,d2) << endl ; 66 67 } 68 } 69 70 return 0 ; 71 }
Palindromic Squares
1 /* 2 ID:xiekeyi1 3 PROG:dualpal 4 LANG:C++ 5 */ 6 #include<bits/stdc++.h> 7 using namespace std ; 8 const int maxn = 100 ; 9 int a[maxn] ; 10 11 12 void f( int a[] , int n , int b , int &d ) 13 { 14 int digit = 0 ; 15 while( n != 0 ) 16 { 17 a[digit++] = n % b ; 18 n /= b ; 19 } 20 d = digit ; 21 return ; 22 } 23 24 bool judge( int a[] , int d ) 25 { 26 for( int i = 0 ; i <= d/2 ; i++) 27 if( a[i] != a[ d-i-1] ) 28 return false ; 29 return true ; 30 } 31 int main() 32 { 33 34 freopen("dualpal.in","r",stdin); 35 freopen("dualpal.out","w",stdout); 36 int n , s ; 37 cin >> n >> s ; 38 int i = 0 ; 39 int temp = s+1 ; 40 for( i = 0 ; i < n ; ) 41 { 42 int flag = 0 ; 43 for( int j = 2 ; j <= 10 ; j++) 44 { 45 int d = 0 ; 46 f(a,temp,j,d); 47 if( judge( a , d ) ) 48 flag++; 49 if( flag >= 2 ) 50 { 51 cout << temp << endl ; 52 i++; 53 break ; 54 } 55 } 56 temp++; 57 } 58 return 0 ; 59 } 60 61
Dual Palindromes
时间: 2024-10-11 03:16:14