https://www.nowcoder.com/acm/contest/90#question
A
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
template <typename cinType>
void getArr ( cinType *a, int n ) {
for ( int i = 0; i < n; i++ )
cin >> a[i];
}
template <typename coutType>
void putArr ( coutType *a, int n ) {
for ( int i = 0; i < n; i++ )
if ( i == n - 1 ) cout << a[i] << endl;
else cout << a[i] << ' ';
}
template <typename reSetType>
void reSet ( reSetType *a, int n, reSetType val ) {
for ( int i = 0; i < n; i++ )
a[i] = val;
}
int main() {
std::ios::sync_with_stdio ( false );
cin.tie ( 0 );
int T, n;
cin >> T;
while ( T-- ) {
cin >> n;
cout << (int)pow ( 2, n - 1 ) << endl;
}
return 0;
}
D
dp的记忆化数组
#include <cstring>
#include <iostream>
using namespace std;
int medp[1400][1400];
char in[1500];
int func1 ( int i, int j ) {
if ( i >= j )
return i == j;
if ( medp[i][j] ) return medp[i][j];
if ( in[i] == in[j] ) {
medp[i + 1][j - 1] = func1 ( i + 1, j - 1 );
return medp[i + 1][j - 1] + 2;
} else {
medp[i + 1][j] = func1 ( i + 1, j );
medp[i][j - 1] = func1 ( i, j - 1 );
return max ( medp[i + 1][j], medp[i][j - 1] );
}
}
int main() {
std::ios::sync_with_stdio ( false );
cin.tie ( 0 );
while ( cin >> in ) {
int len = strlen ( in );
for ( int i = 0; i < len; i++ )
if ( in[i] >= 97 &&in[i] <= 122 )
in[i] -= 32;
memset ( medp, 0, sizeof medp );
cout << len - func1 ( 0, len - 1 ) << endl;
}
return 0;
}
E
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
template <typename cinType>
void getArr ( cinType *a, int n ) {
for ( int i = 0; i < n; i++ )
cin >> a[i].x >> a[i].y;
}
template <typename coutType>
void putArr ( coutType *a, int n ) {
for ( int i = 0; i < n; i++ )
if ( i == n - 1 ) cout << a[i] << endl;
else cout << a[i] << ' ';
}
template <typename reSetType>
void reSet ( reSetType *a, int n, reSetType val ) {
for ( int i = 0; i < n; i++ )
a[i] = val;
}
class coordinate {
public:
int x, y;
} in[1008];
int main() {
std::ios::sync_with_stdio ( false );
cin.tie ( 0 );
int T;
cin >> T ;
while ( T-- ) {
int n;
cin >> n;
getArr<coordinate> ( in, n );
int ans = 0;
for ( int i = 0; i < n; i++ ) {
map<int, int>ma;
for ( int j = 0; j < n; j++ ) {
int temp = ( in[i].x - in[j].x ) * ( in[i].x - in[j].x ) + ( in[i].y - in[j].y ) * ( in[i].y - in[j].y );
ans += ma[temp];
ma[temp]++;
}
}
if ( ans ) cout << ( long long ) ans * 2 << endl;
else cout << "WA" << endl;
}
return 0;
}
F
求x*y=n*n的正整数解,
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
template <typename cinType>
void getArr ( cinType *a, int n ) {
for ( int i = 0; i < n; i++ )
cin >> a[i].x >> a[i].y;
}
template <typename coutType>
void putArr ( coutType *a, int n ) {
for ( int i = 0; i < n; i++ )
if ( i == n - 1 ) cout << a[i] << endl;
else cout << a[i] << ' ';
}
template <typename reSetType>
void reSet ( reSetType *a, int n, reSetType val ) {
for ( int i = 0; i < n; i++ )
a[i] = val;
}
int main() {
std::ios::sync_with_stdio ( false );
cin.tie ( 0 );
int T;
cin >> T ;
while ( T-- ) {
int n;
cin >> n;
int ans = 1;
for ( int i = 2; i <= n && i < 32000; i++ )
if ( n % i == 0 ) {
int flag = 0;
while ( n % i == 0 ) {
flag++;
n = n / i;
}
ans *= flag * 2 + 1;
}
if ( n != 1 )
ans *= 3;
cout << ( ans + 1 ) / 2 << endl;
}
return 0;
}
G
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
template <typename cinType>
void getArr ( cinType *a, int n ) {
for ( int i = 0; i < n; i++ )
cin >> a[i];
}
template <typename coutType>
void putArr ( coutType *a, int n ) {
for ( int i = 0; i < n; i++ )
if ( i == n - 1 ) cout << a[i] << endl;
else cout << a[i] << ' ';
}
template <typename reSetType>
void reSet ( reSetType *a, int n, reSetType val ) {
for ( int i = 0; i < n; i++ )
a[i] = val;
}
int main() {
std::ios::sync_with_stdio ( false );
cin.tie ( 0 );
int T;
cin >> T ;
while ( T-- ) {
int n, m;
char in[40][40];
cin >> n >> m;
for ( int i = 0; i < n; i++ )
cin >> in[i];
int sum = 0;
string s;
cin >> s;
for ( int i = 0; i < s.size(); i++ )
if ( s[i] == 'L' ) sum--;
else sum++;
sum = sum % 4 ;
if ( sum % 2 == 0 ) {
cout << n << ' ' << m << endl;
if ( sum )
for ( int i = n - 1; i >= 0; i-- ) {
for ( int j = m - 1; j >= 0; j-- )
cout << in[i][j];
cout << endl;
}
else for ( int i = 0; i < n; i++ )
cout << in[i] << endl;
} else {
for ( int i = 0; i < n; i++ )
for ( int j = 0; j < m; j++ ) {
if ( in[i][j] == '|' ) in[i][j] = '-';
else if ( in[i][j] == '-' ) in[i][j] = '|';
}
cout << m << ' ' << n << endl;
if ( sum == 1 || sum == -3 )
for ( int j = 0; j < m; j++ ) {
for ( int i = n - 1; i >= 0; i-- )
cout << in[i][j];
cout << endl;
}
else for ( int j = m - 1; j >= 0; j-- ) {
for ( int i = 0; i < n; i++ )
cout << in[i][j];
cout << endl;
}
}
cout << endl;
}
return 0;
}
I
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
template <typename cinType>
void getArr ( cinType *a, int n ) {
for ( int i = 0; i < n; i++ )
cin >> a[i];
}
template <typename coutType>
void putArr ( coutType *a, int n ) {
for ( int i = 0; i < n; i++ )
if ( i == n - 1 ) cout << a[i] << endl;
else cout << a[i] << ' ';
}
template <typename reSetType>
void reSet ( reSetType *a, int n, reSetType val ) {
for ( int i = 0; i < n; i++ )
a[i] = val;
}
const int MOD = 1e9 + 7;
int QuicklyMod ( int x, int y, int mod ) { //蒙哥马利快速幂
long long ans = 1, flag = x;
while ( y ) {
if ( y % 2 )
ans = ( ans * flag ) % mod;
flag = ( flag * flag ) % mod;
y = y / 2;
}
return ans;
}
int main() {
std::ios::sync_with_stdio ( false );
cin.tie ( 0 );
cout<<"ac"<<endl;
return 0;
}
J
从小到大排序,依次使得相邻的元素相同,直至所有值相同
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
template <typename cinType>
void getArr ( cinType *a, int n ) {
for ( int i = 0; i < n; i++ )
cin >> a[i];
}
template <typename coutType>
void putArr ( coutType *a, int n ) {
for ( int i = 0; i < n; i++ )
if ( i == n - 1 ) cout << a[i] << endl;
else cout << a[i] << ' ';
}
template <typename reSetType>
void reSet ( reSetType *a, int n, reSetType val ) {
for ( int i = 0; i < n; i++ )
a[i] = val;
}
int main() {
std::ios::sync_with_stdio ( false );
cin.tie ( 0 );
int T, n, in[100002];
cin >> T;
while ( T-- ) {
cin >> n;
getArr<int> ( in, n );
sort ( in, in + n );
long long ans = in[n - 1];
for ( int i = 1; i < n - 1; i++ )
ans += in[i] - in[0] ;
cout << ans - in[0] << ' ' << ans << endl;
}
return 0;
}
K
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
template <typename cinType>
void getArr ( cinType *a, int n ) {
for ( int i = 0; i < n; i++ )
cin >> a[i];
}
template <typename coutType>
void putArr ( coutType *a, int n ) {
for ( int i = 0; i < n; i++ )
if ( i == n - 1 ) cout << a[i] << endl;
else cout << a[i] << ' ';
}
template <typename reSetType>
void reSet ( reSetType *a, int n, reSetType val ) {
for ( int i = 0; i < n; i++ )
a[i] = val;
}
int main() {
std::ios::sync_with_stdio ( false );
cin.tie ( 0 );
int T, n;
char in[100002];
cin >> T;
while ( T-- ) {
cin >> n >> in;
if ( n == 1 ) {
cout << in << endl;
continue;
}
int m = strlen ( in );
for ( int i = 0; i < n ; i++ )
for ( int j = 0; m > j - n + 1; j += 2 * n - 2 ) {
if ( j - i >= m ) break;
if ( i % ( n - 1 ) != 0 && j != 0 )
cout << in[j - i];
if ( j + i >= m ) break;
cout << in[j + i];
}
cout << endl;
}
return 0;
}
L
快速幂
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
template <typename cinType>
void getArr ( cinType *a, int n ) {
for ( int i = 0; i < n; i++ )
cin >> a[i];
}
template <typename coutType>
void putArr ( coutType *a, int n ) {
for ( int i = 0; i < n; i++ )
if ( i == n - 1 ) cout << a[i] << endl;
else cout << a[i] << ' ';
}
template <typename reSetType>
void reSet ( reSetType *a, int n, reSetType val ) {
for ( int i = 0; i < n; i++ )
a[i] = val;
}
const int MOD = 1e9 + 7;
int QuicklyMod ( int x, int y, int mod ) { //蒙哥马利快速幂
long long ans = 1, flag = x;
while ( y ) {
if ( y % 2 )
ans = ( ans * flag ) % mod;
flag = ( flag * flag ) % mod;
y = y / 2;
}
return ans;
}
int main() {
std::ios::sync_with_stdio ( false );
cin.tie ( 0 );
int T, in[4];
cin >> T;
while ( T-- ) {
cin >> in[0] >> in[1] >> in[2] >> in[3];
if ( QuicklyMod ( in[0], in[1], MOD ) == QuicklyMod ( in[2], in[3], MOD ) )
cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}