蓝桥杯(3.21 刷真题)

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);
			}
		}
	}
}

相关推荐

  1. 1.倍数

    2024-03-22 22:06:03       50 阅读
  2. |04入门

    2024-03-22 22:06:03       45 阅读
  3. |01普及-

    2024-03-22 22:06:03       41 阅读
  4. |01入门

    2024-03-22 22:06:03       38 阅读
  5. --python-32

    2024-03-22 22:06:03       47 阅读
  6. (3.16

    2024-03-22 22:06:03       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-22 22:06:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-22 22:06:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-22 22:06:03       87 阅读
  4. Python语言-面向对象

    2024-03-22 22:06:03       96 阅读

热门阅读

  1. 数据科学详解与人工智能关系

    2024-03-22 22:06:03       43 阅读
  2. 前端逻辑错误或UI崩溃解决问题

    2024-03-22 22:06:03       38 阅读
  3. SQL Server创建存储过程

    2024-03-22 22:06:03       45 阅读
  4. 力扣-283. 移动零

    2024-03-22 22:06:03       47 阅读
  5. 基于STM32的寻迹小车设计详细论文

    2024-03-22 22:06:03       34 阅读
  6. Thingworx高可用集群部署(七)-Zookeeper集群部署

    2024-03-22 22:06:03       42 阅读
  7. Redis切换数据库的详细介绍

    2024-03-22 22:06:03       45 阅读
  8. 洛克王国卡小游戏2

    2024-03-22 22:06:03       39 阅读
  9. Yarn 管理的前端项目转换为使用 npm

    2024-03-22 22:06:03       41 阅读
  10. Redis 产生阻塞的原因,如何找到阻塞的原因

    2024-03-22 22:06:03       39 阅读
  11. 快速排序--C语言

    2024-03-22 22:06:03       44 阅读
  12. 【大数据技术】Hive基本原理以及使用教程

    2024-03-22 22:06:03       44 阅读