P8682 [蓝桥杯 2019 省 B] 等差数列
import java. util. Arrays ;
import java. util. Scanner ;
public class Main {
public static void main ( String [ ] args) {
Scanner sc = new Scanner ( System . in) ;
int n = sc. nextInt ( ) ;
int [ ] res = new int [ n+ 1 ] ;
for ( int i= 1 ; i<= n; i++ )
res[ i] = sc. nextInt ( ) ;
Arrays . sort ( res) ;
int d = Integer . MAX_VALUE ;
for ( int i= 2 ; i<= n; i++ ) {
d = Math . min ( d, res[ i] - res[ i- 1 ] ) ;
}
int t = res[ 1 ] ;
int w = 1 ;
for ( ; t< res[ n] ; ) {
t+= d;
w++ ;
}
System . out. println ( w) ;
}
}
P8615 [蓝桥杯 2014 国 C] 拼接平方数
import java. util. Scanner ;
public class Main {
public static boolean check1 ( String s) {
int t = Integer . valueOf ( s) ;
int st = ( int ) Math . sqrt ( t) ;
return st* st == t;
}
public static boolean check2 ( String s) {
for ( int i= 1 ; i< s. length ( ) ; i++ ) {
String s1 = s. substring ( 0 , i) ;
String s2 = s. substring ( i) ;
if ( s1. equals ( "0" ) || s1. equals ( "00" ) || s1. equals ( "000" ) || s1. equals ( "0000" ) || s1. equals ( "00000" ) || s1. equals ( "000000" ) ) {
return false ;
}
if ( s2. equals ( "0" ) || s2. equals ( "00" ) || s2. equals ( "000" ) || s2. equals ( "0000" ) || s2. equals ( "00000" ) || s2. equals ( "000000" ) ) {
return false ;
}
if ( check1 ( s1) && check1 ( s2) )
return true ;
}
return false ;
}
public static void main ( String [ ] args) {
Scanner sc = new Scanner ( System . in) ;
int l = sc. nextInt ( ) ;
int r = sc. nextInt ( ) ;
for ( int i= l; i<= r; i++ ) {
String s = i+ "" ;
if ( check1 ( s) && check2 ( s) ) {
System . out. println ( i) ;
}
}
}
}
import java. util. Scanner ;
public class Main {
public static boolean check1 ( String s) {
int t = Integer . valueOf ( s) ;
if ( t == 0 )
return false ;
int st = ( int ) Math . sqrt ( t) ;
return st* st == t;
}
public static boolean check2 ( String s) {
for ( int i= 1 ; i< s. length ( ) ; i++ ) {
String s1 = s. substring ( 0 , i) ;
String s2 = s. substring ( i) ;
if ( check1 ( s1) && check1 ( s2) )
return true ;
}
return false ;
}
public static void main ( String [ ] args) {
Scanner sc = new Scanner ( System . in) ;
int l = sc. nextInt ( ) ;
int r = sc. nextInt ( ) ;
for ( int i= l; i<= r; i++ ) {
String s = i+ "" ;
if ( check1 ( s) && check2 ( s) ) {
System . out. println ( i) ;
}
}
}
}