当前位置: 代码迷 >> 综合 >> 2018 蓝桥杯省赛 B 组模拟赛(一)
  详细解决方案

2018 蓝桥杯省赛 B 组模拟赛(一)

热度:142   发布时间:2023-10-20 11:00:57.0
1.

今天蒜头君带着花椰妹和朋友们一起聚会,当朋友们问起年龄的时候,蒜头君打了一个哑谜(毕竟年龄是女孩子的隐私)说:“我的年龄是花椰妹年龄个位数和十位数之和的二倍”。

花椰妹看大家一脸懵逼,就知道大家也不知道蒜头君的年龄,便连忙补充道:“我的年龄是蒜头君个位数和十位数之和的三倍”。

请你计算:蒜头君和花椰妹年龄一共有多少种可能情况?

提醒:两位的年龄都是在 [10,100)

[10,100) 这个区间内。


这个题很水,直接上代码

package day2;public class T1 {public static void main(String[] args) {int a,b,c,d;int i,j;int count=0;for(i=10;i<101;i++){for(j=10;j<101;j++){a=i/10;b=i%10;c=j/10;d=j%10;if(((c+d)*2==(a*10+b)) && ((a+b)*3)==(c*10+d)){count++;System.out.println(a+""+ b +" " + c+"" +d);}}}}
}
2.

蒜头君今天回到了老家的大宅院,老家的灯还是那中拉线的灯(拉一次为亮,再拉一次就灭),蒜头君觉得无聊。把 10001000 盏灯 33 的倍数拉了一次,55 的倍数拉了一次,7的倍数拉了一次(灯得的编号从 1-10001?1000,灯的初始状态都是亮的)。这个时候蒜头君在想还剩下几盏灯还在亮着?

提示:请不要输出多余的符号。

package day2;public class T2 {public static void main(String[] args) {int[] a = new int[1002];int count=0;for(int i=1;i<=1000;i++){a[i]=0;}for(int i=1;i<1001;i++){if(i%3==0){a[i]++;}if(i%5==0){a[i]++;}if(i%7==0){a[i]++;}}for(int i=1;i<=1000;i++){if(a[i]%2==0){count++;}}System.out.println(count);}
}
3.

最近蒜头君喜欢上了U型数字,所谓U型数字,就是这个数字的每一位先严格单调递减,后严格单调递增。比如 212212 就是一个U型数字,但是 33333398985675673131331313,就是不是U型数字。

现在蒜头君问你,[1,100000][1,100000] 有多少U型数字?

提示:请不要输出多余的符号。


package day2;public class T3 {public static void main(String[] args) {int a,b,c;int d,e,f,g;int h,i,j,k,l;int count=0;for(a=0;a<10;a++)for(b=0;b<10;b++)for(c=0;c<10;c++){if(a>b && c>b)count++;}for(d=0;d<10;d++)for(e=0;e<10;e++)for(f=0;f<10;f++)for(g=0;g<10;g++){if(d>e && g>f && e!=f){count++;}}for(h=0;h<10;h++)for(i=0;i<10;i++)for(j=0;j<10;j++)for(k=0;k<10;k++)for(l=0;l<10;l++){if(i>j && h>i && k>j && l>k){count++;}if(l>k && j>k && i>j && h>i){count++;}if(h>i && j>i && k>j && l>k){count++;}}System.out.println(count);}
}

解法二:

package day2;  import java.util.*;  
public class T3 {  public static void main(String[] args){  int a,b,c;  int sum = 0;  for (int i=100;i<=999;i++){  a=i%10;//个  b=i/10%10;//十  c=i/100%10;//百  if (c>b&&b<a){  sum++;  }  }  int x,y,z,n;  for (int i=1000;i<=9999;i++){  x = i%10;  y = i/10%10;  z = i/100%10;  n = i/1000%10;  if (n>z&&y<x&&z!=y){  sum++;  //System.out.println(i);  }  }  int q,w,e,r,t;  for (int i=10000;i<100000;i++){  q = i % 10;  w = i/10%10;  e = i/100%10;  r = i/1000%10;  t = i/10000%10;  if (t>r&&r>e&&e<w&&w<q){  sum++;  }  if (t>r&&r<e&&e<w&&w<q){  sum++;  }  if (t>r&&r>e&&e>w&&w<q){  sum++;  }  }  System.out.println(sum);  }  
}  

4.

LIS是最长上升子序列。什么是最长上升子序列? 就是给你一个序列,请你在其中求出一段最长严格上升的部分,它不一定要连续。

就像这样:22334477 和 22334466 就是序列 22 55 33 44 11 77 66 的两个上升子序列,最长的长度是 44

动态规划的最长上升子序列,动态规划学的不行,回头好好看看

import java.util.*;
import java.math.*;public class Main {public static final int N = 1000;public static int[] f = new int[N];public static int[] b = new int[N];public static int max(int a, int b) {if (a > b) {return a;}return b;}public static int lis(int n) {int res = 0;for (int i = 0; i < n; ++i) {for (int j = 0; j < i; ++j) {if (b[j] < b[i]) {f[i] = max(f[i],f[j]+1);}}res = max(res, f[i]);}return res+1;}public static void main(String[] args) {Scanner cin = new Scanner(System.in);int n = cin.nextInt();for (int i = 0; i < n; ++i) {b[i] = cin.nextInt() ;}System.out.println(lis(n));}
}



补充:

5.

代码填空

相信大家都知道什么是全排列,但是今天的全排列比你想象中的难一点。我们要找的是全排列中,排列结果互不相同的个数。比如:aab 的全排列就只有三种,那就是aab,baa,aba

代码框中的代码是一种实现,请分析并填写缺失的代码。

import java.util.*;
import java.math.*;public class Main {public static final int N = 1000;public static char[] str = new char[N];public static char[] buf = new char[N];public static int[] vis = new int[N];public static int total = 0;public static int len = 0;public static void arrange(int num) {if (num == len) {for (int i = 0; i < len; ++i) {System.out.print(buf[i]);}System.out.println();total++;return;}for (int i = 0; i < len; ++i) {if (vis[i] == 0) {int j = 0;for (j = i + 1; j < len; ++j) {if (vis[j] && str[i]==str[j]) {//缺失的部分break;}}if (j == len) {vis[i] = 1;buf[num] = str[i];arrange(num + 1);vis[i]= 0;}}}}public static void main(String[] args) {Scanner cin = new Scanner(System.in);str = cin.next().toCharArray();total = 0;len = str.length;buf[len] = '\0';int i = 0, j = 0;for (i = 0; i < len; ++i) {for (j = i + 1; j < len; ++j) {if (str[i] > str[j]) {char tmp = str[i];str[i] = str[j];str[j] = tmp;}}}arrange(0);System.out.println("Total " + total);}
}


6.

蒜头君今天突然开始还念童年了,想回忆回忆童年。他记得自己小时候,有一个很火的游戏叫做数独。便开始来了一局紧张而又刺激的高阶数独。蒜头君做完发现没有正解,不知道对不对? 不知道聪明的你能否给出一个标准答案?

标准数独是由一个给与了提示数字的 9 \times 99×9 网格组成,我们只需将其空格填上数字,使得每一行,每一列以及每一个 3 \times 33×3 宫都没有重复的数字出现。

输出这个数独得正解,输出格式如下:

 
 
1
* 2 6 * * * * * *
2
* * * 5 * 2 * * 4
3
* * * 1 * * * * 7
4
* 3 * * 2 * 1 8 *
5
* * * 3 * 9 * * *
6
* 5 4 * 1 * * 7 *
7
5 * * * * 1 * * *
8
6 * * 9 * 7 * * *
9
* * * * * * 7 5 *











把上面的 * 替换成 1 - 91?9 就可以了

提醒:两个数字之间要有一个空格,其他地方不要输出多余的符号。

本题答案不唯一,符合要求的答案均正确

链接:https://blog.csdn.net/qq_32473657/article/details/50927383

传送门



  相关解决方案