A 三连击
#include <iostream>
#include <cstdio>
using namespace std;
bool judge ( int a, int b) {
int a1, a2, a3;
int b1, b2, b3;
a1= a/ 100 , a2= a/ 10 % 10 , a3= a% 10 ;
b1= b/ 100 , b2= b/ 10 % 10 , b3= b% 10 ;
int cnt[ 10 ] ;
for ( int i= 0 ; i< 10 ; i++ ) cnt[ i] = 0 ;
cnt[ a1] ++ , cnt[ a2] ++ , cnt[ a3] ++ ;
cnt[ b1] ++ , cnt[ b2] ++ , cnt[ b3] ++ ;
if ( cnt[ 0 ] >= 1 ) return false ;
for ( int i= 0 ; i< 10 ; i++ ) {
if ( cnt[ i] > 1 ) return false ;
}
return true ;
}
int main ( ) {
for ( int i= 100 ; i<= 333 ; i++ ) {
if ( judge ( i, i* 2 ) && judge ( i, i* 3 ) && judge ( i* 2 , i* 3 ) ) {
printf ( "%d %d %d\n" , i, i* 2 , i* 3 ) ;
}
}
return 0 ;
}
B 三连击加强版
#include <iostream>
#include <cstdio>
using namespace std;
bool judge ( int a, int b) {
int a1, a2, a3;
int b1, b2, b3;
a1= a/ 100 , a2= a/ 10 % 10 , a3= a% 10 ;
b1= b/ 100 , b2= b/ 10 % 10 , b3= b% 10 ;
int cnt[ 10 ] ;
for ( int i= 0 ; i< 10 ; i++ ) cnt[ i] = 0 ;
cnt[ a1] ++ , cnt[ a2] ++ , cnt[ a3] ++ ;
cnt[ b1] ++ , cnt[ b2] ++ , cnt[ b3] ++ ;
if ( cnt[ 0 ] >= 1 ) return false ;
for ( int i= 0 ; i< 10 ; i++ ) {
if ( cnt[ i] > 1 ) return false ;
}
return true ;
}
int main ( ) {
int A, B, C;
scanf ( "%d%d%d" , & A, & B, & C) ;
int cnt= 0 ;
for ( int i= 100 ; i<= 999 ; i++ ) {
if ( i% A== 0 ) {
int j= i/ A* B;
int k= i/ A* C;
if ( j> 999 || k> 999 ) break ;
if ( judge ( i, j) && judge ( i, k) && judge ( j, k) ) {
printf ( "%d %d %d\n" , i, j, k) ;
cnt++ ;
}
}
}
if ( cnt== 0 ) printf ( "No!!!\n" ) ;
return 0 ;
}
C 组合成最大数字
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
bool cmp ( string s1, string s2) {
return s1+ s2> s2+ s1;
}
int main ( ) {
int n;
cin>> n;
string s[ 30 ] ;
for ( int i= 1 ; i<= n; i++ ) cin>> s[ i] ;
sort ( s+ 1 , s+ n+ 1 , cmp) ;
for ( int i= 1 ; i<= n; i++ ) cout<< s[ i] ;
return 0 ;
}
D 跳马
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int dp[ 20 ] [ 20 ] ;
int dir[ 4 ] [ 2 ] = { - 1 , 2 , - 2 , 1 , - 1 , - 2 , - 2 , - 1 } ;
int main ( ) {
int n, m;
scanf ( "%d%d" , & n, & m) ;
memset ( dp, 0 , sizeof ( dp) ) ;
dp[ 0 ] [ 0 ] = 1 ;
for ( int j= 1 ; j<= m; j++ ) {
for ( int i= 0 ; i<= n; i++ ) {
for ( int k= 0 ; k< 4 ; k++ ) {
int ii= i+ dir[ k] [ 1 ] ;
int jj= j+ dir[ k] [ 0 ] ;
if ( ii>= 0 && ii<= n&& jj>= 0 ) {
dp[ i] [ j] + = dp[ ii] [ jj] ;
}
}
}
}
printf ( "%d\n" , dp[ n] [ m] ) ;
return 0 ;
}
E 求数之和
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n, sum, j;
int main ( )
{
cin>> n;
for ( int i= 1 ; i<= n/ 2 ; i++ ) {
sum= 0 ;
for ( j= i; j< n; j++ ) {
sum+ = j;
if ( sum>= n) break ;
}
if ( sum== n) cout<< i<< ' ' << j<< endl;
}
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
int m;
int main ( ) {
cin>> m;
for ( int k1= sqrt ( 2 * m) ; k1> 1 ; k1-- )
if ( 2 * m% k1== 0 && ( k1+ 2 * m/ k1) % 2 ) {
int k2= 2 * m/ k1;
cout<< ( k2- k1+ 1 ) / 2 << " " << ( k1+ k2- 1 ) / 2 << endl;
}
return 0 ;
}
F 筛素数+统计数量
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
int num;
int prime[ 110 ] ;
void get_prime ( ) {
num= 0 ;
bool flag;
for ( int i= 2 ; i<= 100 ; i++ ) {
flag= true ;
for ( int j= 2 ; j< i; j++ ) {
if ( i% j== 0 ) {
flag= false ;
break ;
}
}
if ( flag) prime[ ++ num] = i;
}
}
int main ( ) {
get_prime ( ) ;
int cnt[ 26 ] ;
memset ( cnt, 0 , sizeof ( cnt) ) ;
string s;
cin>> s;
int len= s. size ( ) ;
for ( int i= 0 ; i< len; i++ ) {
cnt[ s[ i] - 'a' ] ++ ;
}
int maxx= 0 , minn= 0x3f3f3f3f ;
for ( int i= 0 ; i< 26 ; i++ ) {
if ( cnt[ i] == 0 ) continue ;
maxx= max ( maxx, cnt[ i] ) ;
minn= min ( minn, cnt[ i] ) ;
}
int p= maxx- minn;
bool flag= false ;
for ( int i= 1 ; i<= num; i++ ) {
if ( p== prime[ i] ) {
flag= true ;
break ;
}
}
if ( flag) printf ( "Lucky Word\n%d\n" , p) ;
else printf ( "No Answer\n0\n" ) ;
return 0 ;
}
G 搜索+逆向求解
#include <iostream>
#include <cstdio>
using namespace std;
int n;
int g[ 100 ] [ 100 ] ;
int dir[ 4 ] [ 2 ] = { 1 , 0 , - 1 , 0 , 0 , 1 , 0 , - 1 } ;
bool judge ( int x, int y) {
if ( x< 1 || x> n|| y< 1 || y> n) return false ;
if ( g[ x] [ y] == 2 || g[ x] [ y] == 1 ) return false ;
return true ;
}
void dfs ( int x, int y) {
g[ x] [ y] = 2 ;
for ( int i= 0 ; i< 4 ; i++ ) {
int tx= x+ dir[ i] [ 0 ] ;
int ty= y+ dir[ i] [ 1 ] ;
if ( judge ( tx, ty) )
dfs ( tx, ty) ;
}
}
int main ( ) {
scanf ( "%d" , & n) ;
for ( int i= 1 ; i<= n; i++ )
for ( int j= 1 ; j<= n; j++ )
scanf ( "%d" , & g[ i] [ j] ) ;
for ( int i= 1 ; i<= n; i++ ) {
if ( g[ i] [ 1 ] == 0 ) dfs ( i, 1 ) ;
if ( g[ i] [ n] == 0 ) dfs ( i, n) ;
if ( g[ 1 ] [ i] == 0 ) dfs ( 1 , i) ;
if ( g[ n] [ i] == 0 ) dfs ( n, i) ;
}
for ( int i= 1 ; i<= n; i++ ) {
for ( int j= 1 ; j<= n; j++ ) {
printf ( "%d" , 2 - g[ i] [ j] ) ;
putchar ( j== n? '\n' : ' ' ) ;
}
}
return 0 ;
}