zoukankan      html  css  js  c++  java
  • Java实现蓝桥杯第十一届校内模拟赛

    有不对的地方欢迎大佬们进行评论(ง •_•)ง
    多交流才能进步,互相学习,互相进步
    蓝桥杯交流群:99979568 欢迎加入 o( ̄▽ ̄)ブ

    有一道题我没写,感觉没有必要写上去就是给你多少MB然后求计算机的字节数

    约数的个数

    二叉树的结点

    带九9的数的个数

    递增三元组

    元音单词的验证

    数位递增的数

    正整数序列的数量

    空地长草

    组织晚会

    约数的个数

    问题描述
      1200000有多少个约数(只计算正约数)。
    答案提交
      这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

    package 第十三次模拟;
    
    import java.util.Scanner;
    
    public class Demo1约数 {
    public static void main(String[] args) {
    	int count=0;
    	for (int i = 1; i <=1200000; i++) {
    		if(1200000%i==0){
    			count++;
    		}
    	}
    	System.out.println(count);
    }
    }
    
    

    树的结点

    问题描述
      一棵包含有2019个结点的树,最多包含多少个叶结点?
    答案提交
      这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

    package 第十三次模拟;
    
    public class Demo3节点 {
    	public static void main(String[] args) {
    		int start=1;
    		int sum=2019;
    		while(sum>=0){
    			sum-=start;
    			start*=2;
    //			System.out.println(sum);
    		}
    		System.out.println(start/2);//1024是我最后一层有多少结点
    		System.out.println(sum);//最后一层有多少没有结点
    		//1024-(28/2)   最后一层没有的结点/2就是上一层的
    	}
    }
    
    
    

    带九9的数的个数

    问题描述
      在1至2019中,有多少个数的数位中包含数字9?
      注意,有的数中的数位中包含多个9,这个数只算一次。例如,1999这个数包含数字9,在计算只是算一个数。
    答案提交
      这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

    package 第十三次模拟;
    
    public class Demo4求带9的数 {
    	public static void main(String[] args) {
    		int count=0;
    	A:	for (int i = 1; i <=2019; i++) {
    			int a=i;
    			while(a!=0){
    				int b = a%10;
    				if(b==9){
    					count++;
    					continue A;
    				}
    				a/=10;
    			}
    		}
    		System.out.println(count);
    	}
    
    }
    
    

    递增三元组

    问题描述
      在数列 a[1], a[2], …, a[n] 中,如果对于下标 i, j, k 满足 0<i<j<k<n+1 且 a[i]<a[j]<a[k],则称 a[i], a[j], a[k] 为一组递增三元组,a[j]为递增三元组的中心。
      给定一个数列,请问数列中有多少个元素可能是递增三元组的中心。
    输入格式
      输入的第一行包含一个整数 n。
      第二行包含 n 个整数 a[1], a[2], …, a[n],相邻的整数间用空格分隔,表示给定的数列。
    输出格式
      输出一行包含一个整数,表示答案。
    样例输入
    5
    1 2 5 3 5
    样例输出
    2
    样例说明
      a[2] 和 a[4] 可能是三元组的中心。
    评测用例规模与约定
      对于 50% 的评测用例,2 <= n <= 100,0 <= 数列中的数 <= 1000。
      对于所有评测用例,2 <= n <= 1000,0 <= 数列中的数 <= 10000。

    import java.util.Scanner;
    
    public class 递增三元组 {
    	public static void main(String[] args) {
    		Scanner in = new Scanner(System.in);
    		int n = in.nextInt();
    		int[] a = new int[n];
    		int[] min = new int[n];
    		int[] max = new int[n];
    		for (int i = 0; i < n; i++)
    			a[i] = in.nextInt();
    		min[0] = a[0];
    		max[n - 1] = a[n - 1];
    		for (int i = 1; i < n; i++) {
    			min[i] = Math.min(a[i], min[i - 1]);
    		}
    		for (int i = n - 2; i >= 0; i--) {
    			max[i] = Math.max(a[i], max[i + 1]);
    		}
    		int cnt = 0;
    		for (int i = 1; i < n - 1; i++) {
    			if (a[i] > min[i - 1] && a[i] < max[i + 1]) {
    				cnt++;
    				//System.out.println(i + 1);
    			}
    		}
    		System.out.print(cnt);
    	}
    
    }
    
    

    元音单词的验证

    问题描述
      小明对类似于 hello 这种单词非常感兴趣,这种单词可以正好分为四段,第一段由一个或多个辅音字母组成,第二段由一个或多个元音字母组成,第三段由一个或多个辅音字母组成,第四段由一个或多个元音字母组成。
      给定一个单词,请判断这个单词是否也是这种单词,如果是请输出yes,否则请输出no。
      元音字母包括 a, e, i, o, u,共五个,其他均为辅音字母。
    输入格式
      输入一行,包含一个单词,单词中只包含小写英文字母。
    输出格式
      输出答案,或者为yes,或者为no。
    样例输入
    lanqiao
    样例输出
    yes
    样例输入
    world
    样例输出
    no
    评测用例规模与约定
      对于所有评测用例,单词中的字母个数不超过100。

    package 第十三次模拟;
    
    import java.util.ArrayList;
    import java.util.Scanner;
    
    public class Demo6元音 {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		String s = sc.next();
    		sc.close();
    		ArrayList<Character> list = new ArrayList<Character>();
    		list.add('a');
    		list.add('e');
    		list.add('i');
    		list.add('o');
    		list.add('u');
    		char [] str = s.toCharArray();
    		boolean bool=false;
    		int temp=0;
    		for (int i = 0; i <str.length; i++) {
    			if(bool){
    				if(!list.contains(str[i])){
    					i--;
    					temp++;
    					bool=false;
    					continue;
    				}
    			}
    			else{
    				if(list.contains(str[i])){
    					i--;
    					temp++;
    					bool=true;
    					continue;
    				}
    			}
    		} 
    		if(temp==3){
    			System.out.println("yes");
    		}
    		else{
    			System.out.println("no");
    		}
    	}
    
    }
    
    

    递增的数的位数

    问题描述
      一个正整数如果任何一个数位不大于右边相邻的数位,则称为一个数位递增的数,例如1135是一个数位递增的数,而1024不是一个数位递增的数。
      给定正整数 n,请问在整数 1 至 n 中有多少个数位递增的数?
    输入格式
      输入的第一行包含一个整数 n。
    输出格式
      输出一行包含一个整数,表示答案。
    样例输入
    30
    样例输出
    26
    评测用例规模与约定
      对于 40% 的评测用例,1 <= n <= 1000。
      对于 80% 的评测用例,1 <= n <= 100000。
      对于所有评测用例,1 <= n <= 1000000。

    package 第十三次模拟;
    
    import java.util.Scanner;
    
    public class Demo7递增数 {
    	public static int n=0,count=0;
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		n = sc.nextInt();
    		sc.close();
    		f(0,1);
    		System.out.println(count-1);
    	}
    	public static  void f(int num,int temp){
    		if(num>n){
    			return;
    		}
    		else{
    //			System.out.println(num);
    			count++;
    		}
    		for (int i = temp; i <10; i++) {
    			f(num*10+i,i);
    		}
    	}
    	
    
    }
    
    

    正整数序列的数量

    问题描述
      小明想知道,满足以下条件的正整数序列的数量:
      1. 第一项为 n;
      2. 第二项不超过 n;
      3. 从第三项开始,每一项小于前两项的差的绝对值。
      请计算,对于给定的 n,有多少种满足条件的序列。
    输入格式
      输入一行包含一个整数 n。
    输出格式
      输出一个整数,表示答案。答案可能很大,请输出答案除以10000的余数。
    样例输入
    4
    样例输出
    7
    样例说明
      以下是满足条件的序列:
      4 1
      4 1 1
      4 1 2
      4 2
      4 2 1
      4 3
      4 4
    评测用例规模与约定
      对于 20% 的评测用例,1 <= n <= 5;
      对于 50% 的评测用例,1 <= n <= 10;
      对于 80% 的评测用例,1 <= n <= 100;
      对于所有评测用例,1 <= n <= 1000。

    PS:两种方法
    第一种简单,第二种比较复杂,效率会高一点点

     
    
    package 第十三次模拟;
    
    import java.util.Scanner;
    
    public class Demo8序列 {
    	public static int n=0,count=0;
    	public static int [] []map ;
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		 n =sc.nextInt();
    		 sc.close();
    		 map = new int [n+1][n+1];
    		 for (int i = 1; i <=n; i++) {
    			map[i][i]=1;
    			map[i][0]=1;
    			map[0][i]=1;
    		}
    		 for (int i = 1; i <=n; i++) {
    			count+=f(n,i);
    			count%=10000;
    //			System.out.println(count);
    		}
    		 System.out.println(count);
    //		 System.out.println(f(4,2));
    		 
    	}
    	public static int f(int x,int y){
    		if(map[x][y]!=0){
    			return map[x][y];
    		}
    		for (int i = Math.abs(x-y)-1; i>=0; i--) {
    			map[x][y]+=f(y,i);
    		}
    		map[x][y]%=10000;
    //		map[y][x]=map[x][y];
    //		System.out.println();
    		return map[x][y];
    	}
    
    }
    
    
    
    
    package 第十三次模拟;
    
    import java.util.Scanner;
    
    public class 正整数序列 {
    	public static int n = 0, count = 0;
    	public static int[][] map;
    
    	public static void main(String[] args) {
    		long start = System.currentTimeMillis();
    		Scanner sc = new Scanner(System.in);
    		n = sc.nextInt();
    		sc.close();
    		map = new int[n + 2][n + 2];
    		for (int i = 1; i <= n; i++) {
    			map[i][i] = 1;
    			map[i][0] = 1;
    			map[0][i] = 1;
    			map[i][i - 1] = 1;
    			map[i - 1][i] = 1;
    			// map[i+1][i]=1;
    			// map[i][i+1]=1;
    
    			// for (int j = i-1; j>=0; j--) {
    			// for (int j2 = Math.abs(i-n)-1; j2 >=0; j2--) {
    			// map[n][i]+=map[i][j2];
    			// }
    			// map[n][i]%=10000;
    			//// }
    			// System.out.println(map[n][i]);
    			// count+=map[n][i];
    		}
    		for (int i = 1; i <= n; i++) {
    			// System.out.print(n+" "+i+" "+map[n][i]+" ");
    			if (map[n][i] == 0) {
    
    				for (int j2 = 0; j2 <= Math.abs(i - n) - 1; j2++) {
    					if (map[i][j2] == 0) {
    						f(i, j2);
    						// for (int j = 0; j<=Math.abs(i-j2)-1; j++) {
    						// map[i][j2]+=map[j2][j];
    						// }
    						// map[j2][i]=map[i][j2];
    					}
    					map[n][i] += map[i][j2];
    					// System.out.print(i+" "+j2+" ");
    				}
    				map[n][i] %= 10000;
    			}
    			// }
    
    			// System.out.println(n+" "+i+" "+map[n][i]);
    			// System.out.println(map[n][i]);
    			count += map[n][i];
    			count %= 10000;
    			// if(map[i][n]==0)
    			map[i][n] = map[n][i];
    			// count+=f(n,i);
    			// count%=10000;
    			//// System.out.println(count);
    		}
    		System.out.println(count);
    		long end = System.currentTimeMillis();
    		System.out.println(end - start);
    		// System.out.println(f(4,2));
    
    	}
    
    	public static int f(int x, int y) {
    		if (map[x][y] != 0) {
    			return map[x][y];
    		}
    		for (int i = Math.abs(x - y) - 1; i >= 0; i--) {
    			map[x][y] += f(y, i);
    		}
    		map[x][y] %= 10000;
    		// map[y][x]=map[x][y];
    		// System.out.println();
    		return map[x][y];
    	}
    
    }
    
    

    空地长草

    问题描述
      小明有一块空地,他将这块空地划分为 n 行 m 列的小块,每行和每列的长度都为 1。
      小明选了其中的一些小块空地,种上了草,其他小块仍然保持是空地。
      这些草长得很快,每个月,草都会向外长出一些,如果一个小块种了草,则它将向自己的上、下、左、右四小块空地扩展,这四小块空地都将变为有草的小块。
      请告诉小明,k 个月后空地上哪些地方有草。
    输入格式
      输入的第一行包含两个整数 n, m。
      接下来 n 行,每行包含 m 个字母,表示初始的空地状态,字母之间没有空格。如果为小数点,表示为空地,如果字母为 g,表示种了草。
      接下来包含一个整数 k。
    输出格式
      输出 n 行,每行包含 m 个字母,表示 k 个月后空地的状态。如果为小数点,表示为空地,如果字母为 g,表示长了草。
    样例输入

    4 5
    .g...
    .....
    ..g..
    .....
    2
    

    样例输出
    gggg.
    gggg.
    ggggg
    .ggg.
    评测用例规模与约定
      对于 30% 的评测用例,2 <= n, m <= 20。
      对于 70% 的评测用例,2 <= n, m <= 100。
      对于所有评测用例,2 <= n, m <= 1000,1 <= k <= 1000。

    package 第十三次模拟;
    
    import java.util.Scanner;
    
    public class Demo9草地 {
    	public static int[][] bool;
    	public static int[] start;
    	public static int[] end;
    	public static char[][] num  ;
    	public static int k = 0, n = 0, m = 0;
    	public static int[] x = { 0, 1, 0, -1 };
    	public static int[] y = { 1, 0, -1, 0 };
    
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		n = sc.nextInt();
    		m = sc.nextInt();
    		  num = new char[n][m];
    		for (int i = 0; i < n; i++) {
    			String s = sc.next();
    			num[i] = s.toCharArray();
    		}
    		k = sc.nextInt();
    		sc.close();
    		start = new int[m * n];
    		end = new int[m * n];
    		int temp = 0;
    		bool = new int[n][m];
    		for (int i = 0; i < n; i++) {
    			for (int j = 0; j < m; j++) {
    				if (num[i][j] == 'g') {
    					start[temp] = i;
    					end[temp++] = j;
    				}
    				else{
    					bool[i][j]=-1;
    				}
    			}
    		}
    		for (int i = 0; i < temp; i++) {
    			dfs(start[i],end[i],k);
    		}
    		for (int i = 0; i < n; i++) {
    			for (int j = 0; j <m; j++) {
    				System.out.print(num[i][j]);
    			}
    			System.out.println();
    		}
    	}
    
    	public static void dfs(int xx, int yy, int kk) {
    		
    		bool[xx][yy]=kk;
    		num[xx][yy]='g';
    		for (int i = 0; i < 4; i++) {
    			int newx = x[i] + xx;
    			int newy = y[i] + yy;
    			if ( newx >= 0 && newy >= 0 && newx < n && newy < m&&  kk - 1 > bool[newx][newy]) {
    				dfs(newx, newy, kk - 1);
    			}
    		}
    	}
    
    }
    
    

    组织晚会

    问题描述
      小明要组织一台晚会,总共准备了 n 个节目。然后晚会的时间有限,他只能最终选择其中的 m 个节目。
      这 n 个节目是按照小明设想的顺序给定的,顺序不能改变。
      小明发现,观众对于晚上的喜欢程度与前几个节目的好看程度有非常大的关系,他希望选出的第一个节目尽可能好看,在此前提下希望第二个节目尽可能好看,依次类推。
      小明给每个节目定义了一个好看值,请你帮助小明选择出 m 个节目,满足他的要求。
    输入格式
      输入的第一行包含两个整数 n, m ,表示节目的数量和要选择的数量。
      第二行包含 n 个整数,依次为每个节目的好看值。
    输出格式
      输出一行包含 m 个整数,为选出的节目的好看值。
    样例输入
    5 3
    3 1 2 5 4
    样例输出
    3 5 4
    样例说明
      选择了第1, 4, 5个节目。
    评测用例规模与约定
      对于 30% 的评测用例,1 <= n <= 20;
      对于 60% 的评测用例,1 <= n <= 100;
      对于所有评测用例,1 <= n <= 100000,0 <= 节目的好看值 <= 100000。

    package 第十三次模拟;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Scanner;
    
    public class Demo10选节目 {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int n = sc.nextInt();
    		int m = sc.nextInt();
    		int[] num = new int[n];
    		int[] order = new int[n];
    		for (int i = 0; i < n; i++) {
    			num[i] = sc.nextInt();
    			order[i] = num[i];
    		}
    		sc.close();
    		Arrays.sort(order);
    		ArrayList<String> list = new ArrayList<String>();
    		for (int i = n - m; i < n; i++) {
    			list.add(order[i]+"");
    		}
    		StringBuilder sb = new StringBuilder("");
    		for (int i : num) {
    			if (list.contains(i+"")) {
    				list.remove(i+"");
    				sb.append(i + " ");
    			}
    		}
    		System.out.println(sb);
    	}
    }
    
    
    
  • 相关阅读:
    stenciljs 学习四 组件装饰器
    stenciljs 学习三 组件生命周期
    stenciljs 学习二 pwa 简单应用开发
    stenciljs ionic 团队开发的方便web 组件框架
    stenciljs 学习一 web 组件开发
    使用npm init快速创建web 应用
    adnanh webhook 框架 hook rule
    adnanh webhook 框架 hook 定义
    adnanh webhook 框架request values 说明
    adnanh webhook 框架execute-command 以及参数传递处理
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13074946.html
Copyright © 2011-2022 走看看