第八届蓝桥杯大赛个人赛省赛(软件类)真题

购物单

在这里插入图片描述
本题无输入,购物单如下,物品名称被隐藏了。
···
**** 180.90 88折
**** 10.25 65折
**** 56.14 9折
**** 104.65 9折
**** 100.30 88折
**** 297.15 半价
**** 26.75 65折
**** 130.62 半价
**** 240.28 58折
**** 270.62 8折
**** 115.87 88折
**** 247.34 95折
**** 73.21 9折
**** 101.00 半价
**** 79.54 半价
**** 278.44 7折
**** 199.26 半价
**** 12.97 9折
**** 166.30 78折
**** 125.50 58折
**** 84.98 9折
**** 113.35 68折
**** 166.57 半价
**** 42.56 9折
**** 81.90 95折
**** 131.78 8折
**** 255.89 78折
**** 109.17 9折
**** 146.69 68折
**** 139.33 65折
**** 141.16 78折
**** 154.74 8折
**** 59.42 8折
**** 85.44 68折
**** 293.70 88折
**** 261.79 65折
**** 11.30 88折
**** 268.27 58折
**** 128.29 88折
**** 251.03 8折
**** 208.39 75折
**** 128.88 75折
**** 62.06 9折
**** 225.87 75折
**** 12.89 75折
**** 34.28 75折
**** 62.16 58折
**** 129.12 半价
**** 218.37 半价
**** 289.69 8折
···
需要说明的是,88折指的是按标价的88%计算,而8折是按80%计算,余者类推。
特别地,半价是按50%计算。

输出一个整数表示小明要从取款机上提取的金额,单位是元。
5200

public class Main001{public static void main(String[] args) {// TODO Auto-generated method stubdouble ans = 180.90    *    88+     10.25    *    65+     56.14    *    90  +     104.65   *    90+     100.30   *    88+     297.15   *    50  +      26.75   *    65+     130.62   *    50+     240.28   *    58+     270.62   *    80+     115.87   *    88+     247.34   *    95+      73.21   *    90+     101.00   *    50+      79.54   *    50+     278.44   *    70+     199.26   *    50+      12.97   *    90+     166.30   *    78+     125.50   *    58+      84.98   *    90+     113.35   *    68+     166.57   *    50+      42.56   *    90+      81.90   *    95+     131.78   *    80+     255.89   *    78+     109.17   *    90+     146.69   *    68+     139.33   *    65+     141.16   *    78+     154.74   *    80+      59.42   *    80+      85.44   *    68+     293.70   *    88+     261.79   *    65+      11.30   *    88+     268.27   *    58+     128.29   *    88+     251.03   *    80+     208.39   *    75+     128.88   *    75+      62.06   *    90+     225.87   *    75+      12.89   *    75+      34.28   *    75+      62.16   *    58+     129.12   *    50+     218.37   *    50+     289.69   *    80;System.out.println(ans/100);}}

纸牌三角形

在这里插入图片描述

class MC {int N = 10, n = 9;int a[] = new int[N];boolean[] st = new boolean[N];int res = 0;boolean check(){int s1 = a[1] + a[2] + a[4] + a[6];int s2 = a[1] + a[3] + a[5] + a[9];int s3 = a[6] + a[7] + a[8] + a[9];if(s1 == s2 && s2 == s3) return true;return false;}void dfs(int cnt){if(cnt == n + 1){if(check()) res ++;}for (int i = 1; i <= n; i++) {if(st[i]) continue;st[i] = true;a[cnt] = i;dfs(cnt + 1);st[i] = false;}}public void run() {dfs(1);System.out.println(res/6);}
}public class Main {public static void main(String[] args) {new MC().run();}
}

承压计算

在这里插入图片描述

7 
5 8 
7 8 8 
9 2 7 2 
8 1 4 9 1 
8 1 8 8 4 1 
7 9 6 1 4 5 4 
5 6 5 5 6 9 5 6 
5 5 4 7 9 3 5 5 1 
7 5 7 9 7 4 7 3 3 1 
4 6 4 5 5 8 8 3 2 4 3 
1 1 3 3 1 6 6 5 5 4 4 2 
9 9 9 2 1 9 1 9 2 9 5 7 9 
4 3 3 7 7 9 3 6 1 3 8 8 3 7 
3 6 8 1 5 3 9 5 8 3 8 1 8 3 3 
8 3 2 3 3 5 5 8 5 4 2 8 6 7 6 9 
8 1 8 1 8 4 6 2 2 1 7 9 4 2 3 3 4 
2 8 4 2 2 9 9 2 8 3 4 9 6 3 9 4 6 9 
7 9 7 4 9 7 6 6 2 8 9 4 1 8 1 7 2 1 6 
9 2 8 6 4 2 7 9 5 4 1 2 5 1 7 3 9 8 3 3 
5 2 1 6 7 9 3 2 8 9 5 5 6 6 6 2 1 8 7 9 9 
6 7 1 8 8 7 5 3 6 5 4 7 3 4 6 7 8 1 3 2 7 4 
2 2 6 3 5 3 4 9 2 4 5 7 6 6 3 2 7 2 4 8 5 5 4 
7 4 4 5 8 3 3 8 1 8 6 3 2 1 6 2 6 4 6 3 8 2 9 6 
1 2 4 1 3 3 5 3 4 9 6 3 8 6 5 9 1 5 3 2 6 8 8 5 3 
2 2 7 9 3 3 2 8 6 9 8 4 4 9 5 8 2 6 3 4 8 4 9 3 8 8 
7 7 7 9 7 5 2 7 9 2 5 1 9 2 6 5 3 9 3 5 7 3 5 4 2 8 9 
7 7 6 6 8 7 5 5 8 2 4 7 7 4 7 2 6 9 2 1 8 2 9 8 5 7 3 6 
5 9 4 5 5 7 5 5 6 3 5 3 9 5 8 9 5 4 1 2 6 1 4 3 5 3 2 4 1 
X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
每个X是一个电子秤,其中最小的X为2086458231,
那么还有其他的X的读数比这个大,求最大的X的读数
题外之意还需要求出最小的X,因为由上面的数求出来最小的X要比208645823小很多
应该是乘了个比例
最后的结果乘这个比例把三角形看成上图好算

答案:72665192664
这里用float算得不对,以后还是有double用double吧

import java.util.Scanner;class MC {int N = 32, n = 30;double[][] a = new double[N][N];public void run() {Scanner sc = new Scanner(System.in);for (int i = 1; i <= n - 1; i++) {for (int j = 1; j <= i; j++) {a[i][j] = sc.nextInt();}}//第30层才得到x,循环到30层for (int i = 2; i <= n; i++) {for (int j = 1; j <= i; j++) {int x = i - 1, y = j - 1;//左边的double div = a[x][y] / 2;a[i][j] += div;//右边的div = a[x][j] / 2;a[i][j] += div;}}double min = Float.MAX_EXPONENT, max = Float.MIN_VALUE;for (int i = 1; i <= n; i++) {min = Math.min(min, a[n][i]);max = Math.max(max, a[n][i]);}long res = (long) (max * 2086458231 / min);System.out.println(res);}
}public class Main {public static void main(String[] args) {new MC().run();}
}

魔方状态

在这里插入图片描述
不会,听说要burnside引理
参考:https://www.cnblogs.com/Emiya-wjk/p/10199867.html

取位数

public class Main{static int len(int x){if(x < 10)  return 1;return len(x / 10 ) + 1;}static int f(int x, int k){if(len(x) - k == 0) return x % 10;return f(x / 10, k); //填空位置}public static void main(String[] args) {int x = 23513;System.out.println(f(x, 3));}
}

太简单了,根上题没得比

最大公共子串

public class Main {static int f(String s1, String s2){char[] c1 = s1.toCharArray();char[] c2 = s2.toCharArray();int[][] a = new int[c1.length + 1][c2.length + 1];int max = 0;for (int i = 1; i < a.length; i++) {for (int j = 1; j < a[i].length; j++) {if(c1[i - 1] == c2[j - 1]){a[i][j] = a[i - 1][j - 1] + 1;//填空位置if(a[i][j] > max) max = a[i][j];}}}return max;}public static void main(String[] args) {int n = f("aabcdkkk", "baabcdadabc");System.out.println(n);}
}

注意求的是字串不是子序列
a[i][j]:s1中前i个与s2中前j个组成的最长公共子串
若相等,则a[i][j]=a[i-1][j-1]+1
否则a[i][j]=0

日期问题

在这里插入图片描述
这道题思维难度不高,不过需要注意细心
需要注意年份和月份的位置;注意输出顺序;注意重复日期
对自己发出疑惑:考的时候我真的会写这么长的代码吗

import java.util.*;class Date{int year, month, day;public Date(int year, int month, int day) {this.year = year;this.month = month;this.day = day;}
}class MC {Date[] res = new Date[30];int k = 0;int[] dm = new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31};boolean is29(int year){return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);}//a:年份的位置,b:月份的位置,c:天的位置int[] a = new int[]{1, 3}, b = new int[]{1, 2}, c = new int[]{1, 2, 3};String[] date = new String[4];public void run() {Scanner sc = new Scanner(System.in);String s = sc.nextLine();String[] split = s.split("/");date[1] = split[0];date[2] = split[1];date[3] = split[2];//循环年份for (int i = 0; i < 2; i++) {//循环月份for (int j = 0; j < 2; j++) {//循环天for (int k = 0; k < 3; k++) {//选的不能相同if(a[i] == b[j] || a[i] == c[k] || b[j] == c[k]) continue;check(date[a[i]], date[b[j]], date[c[k]]);}}}Arrays.sort(res, 0, k, new Comparator<Date>() {@Overridepublic int compare(Date o1, Date o2) {if(o1.year == o2.year){if (o1.month == o2.month){return o1.day - o2.day;}else return o1.month - o2.month;}return o1.year - o2.year;}});for (int i = 0; i < k; i++) {System.out.printf("%d-%02d-%02d\n", res[i].year, res[i].month, res[i].day);}}private void check(String year, String month, String day) {//年份有两个开头的19和20,枚举一下是否符合String tyear = "19"+year;handle(tyear, month, day);tyear = "20"+year;handle(tyear, month, day);}private void handle(String year, String month, String day) {int numYear = Integer.parseInt(year), numMonth = Integer.parseInt(month), numDay = Integer.parseInt(day);//检查年份if(numYear < 1960 || numYear > 2059) return;//判断是否是闰年if(is29(numYear)) dm[2] = 29;//检查月份if (numMonth < 1 || numMonth > 12) return;//检查天if (numDay < 1 || numDay > dm[numMonth]) return;//是个可能的日期,存进去//还有一个坑,添加的日期可能重复boolean f = false;for (int i = 0; i < k; i++) {if (res[i].year == numYear && res[i].month == numMonth && res[i].day == numDay){f = true;break;}}//没有重复就添加if (!f) res[k++] = new Date(numYear, numMonth, numDay);//还原dm[2] = 28;}}public class Main {public static void main(String[] args) {new MC().run();}
}

包子凑数

在这里插入图片描述

还是太菜,看出来是完全背包问题,又想到数论,两者一结合就不会了
跟着大佬走
跟着大佬走

import java.util.Scanner;class MC {//n个物品,物品数无限, 物品体积是v[i]//最大凑不出的数目是(100-1)*(99-1),即最大体积是Nint N = (99 - 1) * (100 - 1) - 1;int n;int[] v = new int[101];boolean[] f = new boolean[N + 10];int gcd(int a, int b) {return b > 0 ? gcd(b, a % b) : a;}public void run() {Scanner sc = new Scanner(System.in);n = sc.nextInt();for (int i = 1; i <= n; i++) {v[i] = sc.nextInt();//能够凑出v[i];f[v[i]] = true;}int d = v[1];for (int i = 2; i <= n; i++) d = gcd(d, v[i]);//这些数的最大公因数不是1,有无数多个数不能凑出if (d != 1) {System.out.println("INF");return;}//完全背包//循环物品for (int i = 1; i <= n; i++) {//循环体积,找有没有恰好能凑出该体积的凑法,若没有设置该体积为falsefor (int j = v[i]; j <= N; j++) {f[j] = f[j] || f[j - v[i]];}}int res = 0;for (int i = 1; i <= N; i++) {if (!f[i]) res++;}System.out.println(res);}
}public class Main {public static void main(String[] args) {new MC().run();}
}

分巧克力

在这里插入图片描述

import java.util.Scanner;//二分长度
class MC {int N = (int) (1e5 + 10);int n, m;int[] a = new int[N], h = new int[N], w = new int[N];int count(int len){int cnt = 0;for (int i = 1; i <= n; i++) {cnt += (h[i] / len) * (w[i] / len);}return cnt;}public void run() {Scanner sc = new Scanner(System.in);n = sc.nextInt();m = sc.nextInt();for (int i = 1; i <= n; i++) {h[i] = sc.nextInt();w[i] = sc.nextInt();}int l = 1, r = N;while (l < r){int mid = l + r  + 1 >> 1;if (count(mid) >= m) l = mid; else r = mid - 1;}System.out.println(l);}
}public class Main {public static void main(String[] args) {new MC().run();}
}

K倍区间在这里插入图片描述


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部