2019年12月蓝桥杯校赛

59 篇文章 0 订阅
8 篇文章 0 订阅

title: 2019年12月蓝桥杯校赛
date: 2019-12-13 17:11:19
categories:

  • 蓝桥杯
    tags:
  • 蓝桥杯

  • 01

问题描述

不超过19000的正整数中,与19000互质的数的个数是多少?

答案提交

package school;

import java.util.ArrayList;
public class test3 {
	public static void main(String[] args){
		int count=0;
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i=2;i<=19000;i++){
			if(19000%i==0){
				for (int j = i; j < 19000;j=j+i) {
					if(list.contains(j))
						continue;
					else {
						list.add(j);
					}
				}
			}
		}
		System.out.print(list.size());
	}
}

结果是11800,反过来说与19000互质的数为7200

  • 02

问题描述

在计算机存储中,15.125GB是多少MB?

答案提交

System.out.print(15.125*1024);

结果:15488

  • 03

问题描述

个包含有2019个结点的有向图,最多包含多少条边?(不允许有重边)

答案提交

System.out.print((2019*2020)/2);

4074342

  • 04

问题描述

问题描述

由1对括号,可以组成一种合法括号序列:()

由2对括号,可以组成两种合法括号序列:()()、(())

由4对括号组成的合法括号序列一共有多少种?

由4对括号组成的合法括号序列共有多少种?

答案提交

其前几项为(从第零项开始) : 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 6564120420, 24466267020, 91482563640, 343059613650, 1289904147324, 4861946401452, ...
  • 05

问题描述
给定正整数 n,请问在整数 1 至 n 中,数字中没有数位相同的数有多少个?
例如,当 n=30 时,除开 11 和 22 以外,其他的数都没有数位相同,因此答案为 28。
输入格式
输入的第一行包含一个整数 n。
输出格式
输出一行包含一个整数,表示答案。
样例输入
30
样例输出
28
评测用例规模与约定
对于 40% 的评测用例,1 <= n <= 1000。
对于 80% 的评测用例,1 <= n <= 100000。
对于所有评测用例,1 <= n <= 1000000。

代码:

import java.util.Scanner;

public class answer1 {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int m = in.nextInt();
		int result = 0;
		in.close();
		for(int i=10;i<=m;i++){
			if (judge(i)==true) {
				result++;
			}
		}
		System.out.print(m-result);
	}
	public static boolean judge(int number){
		int i = number%10;
		while(number>0){
			if(i!=number%10)
				return false;
			number = number/10;
		}
		return true;
	}
}

  • 06

问题描述

给定一个单词,请计算这个单词中有多少个元音字母,多少个辅音字母。

元音字母包括 a, e, i, o, u,共五个,其他均为辅音字母。

输入格式

输入一行,包含一个单词,单词中只包含小写英文字母。

输出格式

输出两行,第一行包含一个整数,表示元音字母的数量。第二行包含一个整数,表示辅音字母的数量。

样例输入

lanqiao

样例输出

43

评测用例规模与约定

对于所有评测用例,单词中的字母个数不超过100

import java.util.HashMap;
import java.util.Scanner;

public class answer2 {
	public static void main(String[] args){
		Scanner inScanner  = new Scanner(System.in);
		String string = inScanner.nextLine();
		inScanner.close();
		HashMap<Character, Integer> map = new HashMap<Character, Integer>();
		map.put('a', 0);
		map.put('e', 0);
		map.put('i', 0);
		map.put('o', 0);
		map.put('u', 0);
		int count=0;
		for(int i=0;i<string.length();i++){
			if(map.containsKey(string.charAt(i)))
				count++;
		}
		System.out.println(count);
		System.out.println(string.length()-count);
	}
}

  • 07

问题描述

小明非常不喜欢数字 2,包括那些数位上包含数字 2 的数。如果一个数的数位不包含数字 2,小明将它称为洁净数。请问在整数 1 至 n 中,洁净数有多少个?

输入格式输

入的第一行包含一个整数 n。

输出格式

输出一行包含一个整数,表示答案。

样例输入

30

样例输出

18

评测用例规模与约定

对于 40% 的评测用例,1 <= n <= 10000。

对于 80% 的评测用例,1 <= n <= 100000。

对于所有评测用例,1 <= n <= 1000000。

import java.util.Scanner;
public class answer3 {
	public static void main(String[] args){
		Scanner inScanner = new Scanner(System.in);
		int number = inScanner.nextInt();
		inScanner.close();
		int count = 0;
		for(int i=1;i<=number;i++){
			if(judge(i)==true){
				count++;
			}
		}
		System.out.print(count);
	}
	public static boolean judge(int number){
		int i = 2;
		while(number>0){
			if(i==number%10)
				return false;
			number = number/10;
		}
		return true;
	}
}

  • 08

问题描述
给定一个序列 a_1, a_2, …, a_n。其中 a_1 是最大的数,没有其他数与 a_1 相等。
对于从第二个数开始的每个数 a_i,请找到位置在 a_i 之前且比 a_i 大的,位置上距离 a_i 最近的数 a_j。称 i-j 为 a_i 的前向距离。
对于给定的序列,请求出所有数的前向距离之和。
输入格式
输入的第一行包含一个整数 n,表示序列的长度。
第二行包含 n 个正整数,为给定的序列。
输出格式
输出一个整数,表示序列中所有数的前向距离之和。
样例输入
8
9 1 3 5 2 7 6 3
样例输出
14
样例说明
序列中从第二项开始的前向距离依次为:
1, 2, 3, 1, 5, 1, 1
和为14。
数据规模和约定
对于70%的评测用例,1 <= n <= 1000;
对于所有评测用例,1 <= n <= 100000,a_1 <= 1000000。
请注意答案可能很大,可能需要使用 long long 来保存

import java.util.Scanner;
public class answer4 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int m = in.nextInt();
		int[] num = new int[m];
		for(int i=0;i<m;i++){
			num[i] = in.nextInt();
		}
		in.close();
		long count=0;
		for(int i=1;i<m;i++){
			int j=i-1;
			while(j>=0){
				if(num[j]>num[i]){
					count+=(i-j);
					break;
				}
				j--;
			}
		}
		System.out.print(count);
	}
}

  • 09

问题描述
小明用积木搭了一个城堡。
为了方便,小明在搭的时候用的是一样大小的正方体积本,搭在了一个 n 行 m 列的方格图上,每个积木正好占据方格图的一个小方格。
当然,小明的城堡并不是平面的,而是立体的。小明可以将积木垒在别的积木上面。当一个方格上的积木垒得比较高时,就是一个高塔,当一个方格上没有积木时,就是一块平地。
小明的城堡可以用每个方格上垒的积木层数来表示。例如,下面就表示一个城堡。
9 3 3 1
3 3 3 0
0 0 0 0
这个城堡南面和东面都有空地,西北面有一个大房子,在西北角还有一个高塔,东北角有一个车库。
现在,格格巫要来破坏小明的城堡,他施了魔法水淹小明的城堡。
如果水的高度为1,则紧贴地面的那些积木要被水淹,在上面的例子中,有7块积木要被水淹。
如果水的高度为2,则更多积木要被水淹,在上面的例子中,有13块积木要被水淹。
给定小明的城堡图,请问,水的高度依次为1, 2, 3, …, H 时,有多少块积木要被水淹。
输入格式
输入的第一行包含两个整数 n, m。
接下来 n 行,每行 m 个整数,表示小明的城堡中每个位置积木的层数。
接下来包含一个整数 H,表示水高度的上限。
输出格式
输出 H 行,每行一个整数。第 i 的整数表示水的高度为 i 时被水淹的积木数量。
样例输入
3 4
9 3 3 1
3 3 3 0
0 0 0 0
10
样例输出
7
13
19
20
21
22
23
24
25
25
评测用例规模与约定
对于 40% 的评测用例,1 <= n, m <= 100,1 <= H <= 100,积木层数不超过100;
对于 70% 的评测用例,1 <= n, m <= 1000,1 <= H <= 1000,积木层数不超过1000;
对于所有评测用例,1 <= n, m <= 1000,1 <= H <= 100000,积木层数不超过1000000000。

import java.util.Scanner;
import java.util.Arrays;
public class answer5 {
	public static void main(String[] args){
		Scanner inScanner  =  new Scanner(System.in);
		int m = inScanner.nextInt();
		int n = inScanner.nextInt();
		int[] num = new int[m*n];
		for(int i=0;i<m*n;i++){
			num[i] = inScanner.nextInt();
		}
		int high = inScanner.nextInt();
		inScanner.close();
		Arrays.sort(num);
		int[] result = new int[high];
		int c = 0;
		for(int i=1;i<=high;i++){
			for(int j=m*n-1;j>=0;j--){
				if(num[j]==0)
					break;
				else if (num[j]<=i) {
					result[c] += num[j];
				}else {
					result[c] += i;
				}
			}
			c++;
		}
		for(int i=0;i<high;i++){
			System.out.println(result[i]);
		}
	}
}


  • 10

问题描述
受大西线调水工程启发,小明也准备设计一条调水的水渠。
小明经费有限,他只能在一块有限区域内建立一条简单的水渠。
小明首先勘探了地形,在这块地中有一处水源,必须用作水渠的起点。另外,小明还测量了一些点,包括点的位置和高度。如果两个小明测量的点之间的距离不超过 d 且高度不同,小明就可以在这两点之间建立一段水渠,让水从高处流向低处,这一段的长度为两点之间的直线距离(即将横坐标的差的平方加上纵坐标的差的平方加上高度差的平方后再开平方根)。
小明计划只修一条主水渠,不建立分支的水渠。由于水渠能影响的范围与水渠的长度正相关,小明希望水渠尽可能长。
请注意,水渠必须从水源开始修,并且高度应当递减。水渠的不同段可能交叉(建个桥即可)。
输入格式
输入的第一行包含一个整数 n ,表示小明已经测量的点数。
接下来 n 行,每行三个整数 x, y, h,分别表示测量的点坐标为 (x, y),高度为 h。这部分的第一个点即为水源,第一个点的h值大于其他点的h值。
接下来一行包含一个整数 d。
输出格式
输出一行,包含一个实数,四舍五入保留 2 位小数,表示水渠最长能修多长。
样例输入
5
1 1 10
2 3 8
4 5 9
1 2 5
4 5 5
8
样例输出
10.66
样例说明
在这些点中有两个坐标为 (4, 5) 的点,这是允许的。
评测用例规模与约定
对于 30% 的评测用例,1 <= n <= 10;
对于 60% 的评测用例,1 <= n <= 20;
对于所有评测用例,1 <= n <= 1000,0 <= h <= 10000,0 <= x, y <= 10000,0 < d < 1e7(10的7次方)。

import java.util.Scanner;
class node{
	public int x;
	public int y;
	public int h;
	public node(int x, int y,int h){
		this.x = x;
		this.y = y;
		this.h = h;
	}
}
public class answer6 {
	public static double max = 0;
	public static node[] res;
	public static int d;
	public static void main(String[] args){
		Scanner inScanner = new Scanner(System.in);
		int n = inScanner.nextInt();
		res = new node[n];
		for(int i=0;i<n;i++){
			res[i] = new node(inScanner.nextInt(), inScanner.nextInt(), inScanner.nextInt());
		}
		d = inScanner.nextInt();
		inScanner.close();
		for(int i=1;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if (res[j].h>res[i].h) {
					node l1Node = res[j];
					res[j] = res[i];
					res[i] = l1Node;
				}
			}
		}
		find(0, 0);
		System.out.printf("%.2f",max);
	}
	public static void find(int index,double sum){
		if(sum>max)
			max = sum;
		for(int i=index+1;i<res.length;i++){
			if (res[i].h<res[index].h) {
				double round = Math.sqrt((res[i].x - res[index].x) * (res[i].x - res[index].x) + (res[i].y - res[index].y) * (res[i].y - res[index].y));
				double longlength = Math.sqrt((res[i].x - res[index].x) * (res[i].x - res[index].x) + (res[i].y - res[index].y) * (res[i].y - res[index].y) + (res[i].h - res[index].h) * (res[i].h - res[index].h));
				if (round <= d) {
					find(i, sum + round);
				}
			}
		}
	}
}


  • 11
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值