蓝桥杯历年真题及解析.
package JC2019;
public class A {
public static boolean check(int i){
int x;
while(i>0){
x=i%10;
i/=10;
if(x==2||x==0||x==1||x==9){
return true;
}
}
return false;
}
public static void main(String[] args) {
long sum=0;
for(int i=0;i<=2019;i++){
if(check(i)){
sum+=i;
}
}
System.out.println(sum);
}
}
package JC2019;
public class B {
public static int count=0;
public static void f(int w,int h){
if(w==0||h==0){
return;
}
if(w>=h){
count++;
f(w-h,h);
}
else if(w<h){
count++;
f(w,h-w);
}
}
public static void main(String[] args) {
f(2019,324);
System.out.println(count);
}
}
package JC2019;
import java.util.HashSet;
public class C {
public static void main(String[] args) {
String s="0100110001010001";
HashSet<String> set=new HashSet<String>();
for(int i=0;i<=s.length();i++){
for(int j=i;j<=s.length();j++){
String ss=s.substring(i,j);
set.add(ss);
}
}
System.out.println(set.size()-1);
}
}
package JC2019;
public class D {
public static boolean check(int n){
for(int i=2;i<=Math.sqrt(n);i++){
if((n/i)*i==n){
return false;
}
}
return true;
}
public static void main(String[] args) {
int arr[]=new int [2019];
boolean is[]=new boolean[100000];
int p=0;
for(int i=2;i<is.length;i++){
if(is[i])continue;
else if(check(i)){
arr[p]=i;
p++;
if(p==2019)break;
for(int j=i;j<is.length;j+=i){
is[j]=true;
}
}
}
System.out.println(arr[2018]);
}
}
package JC2019;
public class E {
public static void main(String[] args) {
System.out.println(49-16+1);
}
}
package JC2019;
import java.util.Scanner;
public class F {
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int n=sc.nextInt(),m=sc.nextInt();
int tran[][]=new int[m][n];
for(int i=n-1;i>=0;i--){
for(int j=0;j<m;j++){
tran[j][i]=sc.nextInt();
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
System.out.print(tran[i][j]+" ");
}
System.out.println();
}
}
}
package JC2019;
import java.util.Scanner;
public class G {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), m = sc.nextInt(), t = sc.nextInt();
int arr[][] = new int[t + 1][n + 1];
for (int i = 0; i < m; i++) {
arr[sc.nextInt()][sc.nextInt()]++;
}
int cur[] = new int[n + 1];
for (int i = 1; i < t + 1; i++) {
for (int j = 1; j < n + 1; j++) {
if (arr[i][j] > 0) {
arr[i][j] = arr[i - 1][j] + arr[i][j] * 2;
if (arr[i][j] > 5)
cur[j] = 1;
} else {
if (arr[i - 1][j] > 0) {
arr[i][j] = arr[i - 1][j] - 1;
if (arr[i][j] < 4)
cur[j] = 0;
}
}
}
}
int ans = 0;
for (int i = 0; i < cur.length; i++) {
ans += cur[i];
}
System.out.println(ans);
}
}
package JC2019;
import java.util.Scanner;
import java.util.Vector;
public class H {
static boolean jiancha(char C){
if ((C>='a'&&C<='z')||(C>='A'&&C<='Z')) {
return false;
}
return true;
}
public static void main(String[] args) {
Vector<Integer> vectora = new Vector<Integer>();
Vector<Integer> vectorb = new Vector<Integer>();
int n;
String string;
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
string = scanner.nextLine();
string = scanner.nextLine();
for (int i = 0; i+5 <= string.length(); i++) {
if ((i==0 || jiancha(string.charAt(i-1)) == true) && (i+5==string.length() || jiancha(string.charAt(i+5)) == true)) {
if (string.substring(i, i+5).equals("Alice")) {
vectora.add(i);
}
}
}
for (int i = 0; i+3 <= string.length(); i++) {
if ((i==0 || jiancha(string.charAt(i-1)) == true) && (i+3==string.length() || jiancha(string.charAt(i+3)) == true)) {
if (string.substring(i, i+3).equals("Bob")) {
vectorb.add(i);
}
}
}
int ans = 0;
for (int i = 0; i < vectora.size(); i++) {
int l =0,r=-1;
while(r+1 < vectorb.size() && vectora.get(i) > vectorb.get(r+1) ) {
r++;
}
while (l<=r && vectora.get(i) >vectorb.get(l)+n+3 ) {
l++;
}
ans += r-l+1;
}
for (int i = 0; i < vectorb.size(); i++) {
int l =0,r=-1;
while(r+1 < vectora.size() && vectorb.get(i) > vectora.get(r+1) ) {
r++;
}
while (l<=r && vectorb.get(i) >vectora.get(l)+n+5 ) {
l++;
}
ans += r-l+1;
}
System.out.println(ans);
}
}
package JC2019;
import java.util.Arrays;
import java.util.Scanner;
public class I {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
Arrays.sort(arr);
int set[]=new int[n-1];
for(int i=0;i<n-1;i++){
set[i]=arr[i+1]-arr[i];
}
Arrays.sort(set);
System.out.println((arr[n-1]-arr[0])/set[0]+1);
}
}
package JC2019;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class J {
public static int n;
public static int arr[];
public static int ans=Integer.MAX_VALUE;
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
n=sc.nextInt();
int k=sc.nextInt();
arr=new int[k+1];
for(int i=1;i<=k;i++){
arr[i]=sc.nextInt();
}
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
dfs(1,0,0);
System.out.println((ans-1)*2);
}
public static void dfs(int k,int max,int up){
if(k==1){
dfs(k+1,0,arr[1]);
}
else if(k==arr.length){
max=max>(up+n-arr[k-1])?max:(up+n-arr[k-1]);
ans=max>ans?ans:max;
}
else {
if(arr[k]-arr[k-1]==0){
dfs(k+1,max,up);
}else
for(int i=0;i<(arr[k]-arr[k-1]);i++){
dfs(k+1,max>(up+i)?max:(up+i),arr[k]-arr[k-1]-i);
}
}
}
}