第六届蓝桥杯java B组国赛题目

第六届蓝桥杯java B组国赛题目

1.标题:分机号
X老板脾气古怪,他们公司的电话分机号都是3位数,老板规定,所有号码必须是降序排列,且不能有重复的数位。比如:
751,520,321 都满足要求,而,
766,918,201 就不符合要求。
现在请你计算一下,按照这样的规定,一共有多少个可用的3位分机号码?
请直接提交该数字,不要填写任何多余的内容。

直接全排然后再截取前三个看是否符合降序排列。

我的答案:120

  1. public class Main {  
  2.     static int a[] = {0,1,2,3,4,5,6,7,8,9};  
  3.     static int ans = 0;  
  4.     public static void main(String[] args) {  
  5.           
  6.         dfs(0);  
  7.         System.out.println(ans);  
  8.     }  
  9.     static void dfs(int offset) {  
  10.         if(offset == 3) {  
  11.             if(a[0] > a[1] && a[1] > a[2]) {  
  12.                 ans++;  
  13.             }  
  14.             //System.out.println(a[0] + ” ” +  a[1] + ” ” + a[2]);  
  15.             return;  
  16.         }  
  17.         for(int i = offset; i <= 9; i++) {  
  18.             swap(i, offset);  
  19.             dfs(offset + 1);  
  20.             swap(i, offset);  
  21.         }  
  22.     }  
  23.       
  24.     static void swap(int aa, int b) {  
  25.         int temp = a[aa];  
  26.         a[aa] = a[b];  
  27.         a[b] = temp;  
  28.     }  
  29. }  
public class Main {
    static int a[] = {0,1,2,3,4,5,6,7,8,9};
    static int ans = 0;
    public static void main(String[] args) {

        dfs(0);
        System.out.println(ans);
    }
    static void dfs(int offset) {
        if(offset == 3) {
            if(a[0] > a[1] && a[1] > a[2]) {
                ans++;
            }
            //System.out.println(a[0] + " " +  a[1] + " " + a[2]);
            return;
        }
        for(int i = offset; i <= 9; i++) {
            swap(i, offset);
            dfs(offset + 1);
            swap(i, offset);
        }
    }

    static void swap(int aa, int b) {
        int temp = a[aa];
        a[aa] = a[b];
        a[b] = temp;
    }
}



2.标题:五星填数
如【图1.png】的五星图案节点填上数字:1~12,除去7和11。
要求每条直线上数字和相等。
如图就是恰当的填法。
请你利用计算机搜索所有可能的填法有多少种。
注意:旋转或镜像后相同的算同一种填法。
请提交表示方案数目的整数,不要填写任何其它内容。


思路: 全排,判断符合条件的,再总数除以10

答案: 12

  1. public class Main {  
  2.     static int a[] = {1,2,3,4,5,6,8,9,10,12};  
  3.     static int ans = 0;  
  4.     public static void main(String[] args) {  
  5.           
  6.         dfs(0);  
  7.         System.out.println(ans/10);  
  8.     }  
  9.     static void dfs(int offset) {  
  10.         if(offset == 10) {  
  11.             if(test()) {  
  12.                 ans++;  
  13.             }  
  14.             return;  
  15.         }  
  16.         for(int i = offset; i <= 9; i++) {  
  17.             swap(i, offset);  
  18.             dfs(offset + 1);  
  19.             swap(i, offset);  
  20.         }  
  21.     }  
  22.       
  23.     static boolean test() {  
  24.         boolean check = false;  
  25.         int sum = a[0] + a[2] + a[5] + a[8];  
  26.         if(a[1] + a[2] + a[3] + a[4] != sum) {  
  27.             check = true;  
  28.         }  
  29.         if(a[0] + a[3] + a[6] + a[9] != sum) {  
  30.             check = true;  
  31.         }  
  32.         if(a[1] + a[5] + a[7] + a[9] != sum) {  
  33.             check = true;  
  34.         }  
  35.         if(a[4] + a[6] + a[7] + a[8] != sum) {  
  36.             check = true;  
  37.         }  
  38.         return !check;  
  39.     }  
  40.     static void swap(int aa, int b) {  
  41.         int temp = a[aa];  
  42.         a[aa] = a[b];  
  43.         a[b] = temp;  
  44.     }  
  45. }  
public class Main {
    static int a[] = {1,2,3,4,5,6,8,9,10,12};
    static int ans = 0;
    public static void main(String[] args) {

        dfs(0);
        System.out.println(ans/10);
    }
    static void dfs(int offset) {
        if(offset == 10) {
            if(test()) {
                ans++;
            }
            return;
        }
        for(int i = offset; i <= 9; i++) {
            swap(i, offset);
            dfs(offset + 1);
            swap(i, offset);
        }
    }

    static boolean test() {
        boolean check = false;
        int sum = a[0] + a[2] + a[5] + a[8];
        if(a[1] + a[2] + a[3] + a[4] != sum) {
            check = true;
        }
        if(a[0] + a[3] + a[6] + a[9] != sum) {
            check = true;
        }
        if(a[1] + a[5] + a[7] + a[9] != sum) {
            check = true;
        }
        if(a[4] + a[6] + a[7] + a[8] != sum) {
            check = true;
        }
        return !check;
    }
    static void swap(int aa, int b) {
        int temp = a[aa];
        a[aa] = a[b];
        a[b] = temp;
    }
}

3.标题:显示二叉树
排序二叉树的特征是:
某个节点的左子树的所有节点值都不大于本节点值。
某个节点的右子树的所有节点值都不小于本节点值。
为了能形象地观察二叉树的建立过程,小明写了一段程序来显示出二叉树的结构来。
class BiTree
{
private int v;
private BiTree l;
private BiTree r;

public BiTree(int v){
this.v = v;
}

public void add(BiTree the){
if(the.v < v){
if(l==null) l = the;
else l.add(the);
}
else{
if(r==null) r = the;
else r.add(the);
}
}

public int getHeight(){
int h = 2;
int hl = l==null? 0 : l.getHeight();
int hr = r==null? 0 : r.getHeight();
return h + Math.max(hl,hr);
}

public int getWidth(){
int w = (“”+v).length();
if(l!=null) w += l.getWidth();
if(r!=null) w += r.getWidth();
return w;
}

public void show(){
char[][] buf = new char[getHeight()][getWidth()];
printInBuf(buf, 0, 0);
showBuf(buf);
}

private void showBuf(char[][] x){
for(int i=0; i<x.length; i++){
for(int j=0; j<x[i].length; j++)
System.out.print(x[i][j]==0? ’ ‘:x[i][j]);
System.out.println();
}
}

private void printInBuf(char[][] buf, int x, int y){
String sv = “” + v;

int p1 = l==null? x : l.getRootPos(x);
int p2 = getRootPos(x);
int p3 = r==null? p2 : r.getRootPos(p2+sv.length());

buf[y][p2] = ‘|’;
for(int i=p1; i<=p3; i++) buf[y+1][i]=’-‘;
for(int i=0; i<sv.length(); i++) ________________________________;  //填空位置
if(p1<p2) buf[y+1][p1] = ‘/’;
if(p3>p2) buf[y+1][p3] = ‘\\’;

if(l!=null) l.printInBuf(buf,x,y+2);
if(r!=null) r.printInBuf(buf,p2+sv.length(),y+2);
}

private int getRootPos(int x){
return l==null? x : x + l.getWidth();
}
}


public class Main
{
public static void main(String[] args)
{
BiTree tree = new BiTree(500);
tree.add(new BiTree(200));
tree.add(new BiTree(509));
tree.add(new BiTree(100));
tree.add(new BiTree(250));
tree.add(new BiTree(507));
tree.add(new BiTree(600));
tree.add(new BiTree(650));
tree.add(new BiTree(450));
tree.add(new BiTree(510));
tree.add(new BiTree(440));
tree.add(new BiTree(220));
tree.show();
}
}


对于上边的测试数据,应该显示出:
                  |
   /————–500—\
   |                    |
/–200—\           /–509—\
|        |           |        |
100   /–250—\     507   /–600\
      |        |           |     |
      220   /–450         510   650
            |
            440

(如有对齐问题,请参考【图1.png】)
请分析程序逻辑,填写划线部分缺失的代码。
注意,只填写缺少的部分,不要填写已有的代码或符号,也不要加任何说明文字。


我的答案:buf[y+1][p2+i] = sv.charAt(i);


4.标题:穿越雷区
X星的坦克战车很奇怪,它必须交替地穿越正能量辐射区和负能量辐射区才能保持正常运转,否则将报废。
某坦克需要从A区到B区去(A,B区本身是安全区,没有正能量或负能量特征),怎样走才能路径最短?
已知的地图是一个方阵,上面用字母标出了A,B区,其它区都标了正号或负号分别表示正负能量辐射区。
例如:
A + - + -
- + - - +
- + + + -
+ - + - +
B + - + -
坦克车只能水平或垂直方向上移动到相邻的区。
数据格式要求:
输入第一行是一个整数n,表示方阵的大小, 4<=n<100
接下来是n行,每行有n个数据,可能是A,B,+,-中的某一个,中间用空格分开。
A,B都只出现一次。
要求输出一个整数,表示坦克从A区到B区的最少移动步数。
如果没有方案,则输出-1
例如:
用户输入:
5
A + - + -
- + - - +
- + + + -
+ - + - +
B + - + -
则程序应该输出:
10
资源约定:
峰值内存消耗(含虚拟机) < 512M
CPU消耗  < 2000ms

思路:典型的深搜加回溯

  1. import java.util.Scanner;  
  2.   
  3. public class Main{  
  4.     public static int xA,yA,xB,yB; //记录A和B的坐标  
  5.     public static char[][] map;  
  6.     public static int[][] book;  
  7.     public static int n;   
  8.     private static int stepMin = Integer.MAX_VALUE;  
  9.     private static int[][] next = {{-1,0},{1,0},{0,1},{0,-1}};  
  10.     public static void main(String[] args) {  
  11.         Scanner sc = new Scanner(System.in);  
  12.         n = sc.nextInt();  
  13.         map = new char[n][n];  
  14.         book = new int[n][n];  
  15.         for(int i = 0; i < n; i++) {  
  16.             for(int j = 0; j < n; j++) {  
  17.                 char temp = sc.next().charAt(0);  
  18.                 if(temp == ’+’ || temp == ’-‘) {  
  19.                     map[i][j] = temp;  
  20.                 }else if(temp == ‘A’) {  
  21.                     xA = i;  
  22.                     yA = j;  
  23.                     map[i][j] = ‘A’;  
  24.                 }else if(temp == ‘B’) {  
  25.                     xB = i;  
  26.                     yB = j;  
  27.                     map[i][j] = ‘B’;  
  28.                 }  
  29.             }  
  30.         }  
  31.         book[xA][yA] = 1;  
  32.         dfs(xA,yA,’0’, 0);  
  33.         System.out.println(stepMin);  
  34.     }  
  35.     public static void dfs(int x, int y, char ch, int step) {  
  36.         if(x == xB && y == yB) {  
  37.             if(stepMin > step) {  
  38.                 stepMin = step;  
  39.             }  
  40.             return ;  
  41.         }  
  42.         int tx, ty;  
  43.         for(int i = 0; i < 4; i++) {  
  44.             tx  = x + next[i][0];  
  45.             ty = y + next[i][1];  
  46.             if(tx < 0 || ty < 0 || tx >= n || ty >= n) {  
  47.                 continue;  
  48.             }  
  49.             if(map[tx][ty] != ch && book[tx][ty] == 0 ){  
  50.                 book[tx][ty] = 1;  
  51.                 dfs(tx, ty, map[tx][ty], step + 1);  
  52.                 book[tx][ty] = 0;  
  53.             }  
  54.         }  
  55.     }  
  56. }  
import java.util.Scanner;

public class Main{
    public static int xA,yA,xB,yB; //记录A和B的坐标
    public static char[][] map;
    public static int[][] book;
    public static int n; 
    private static int stepMin = Integer.MAX_VALUE;
    private static int[][] next = {{-1,0},{1,0},{0,1},{0,-1}};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        map = new char[n][n];
        book = new int[n][n];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                char temp = sc.next().charAt(0);
                if(temp == '+' || temp == '-') {
                    map[i][j] = temp;
                }else if(temp == 'A') {
                    xA = i;
                    yA = j;
                    map[i][j] = 'A';
                }else if(temp == 'B') {
                    xB = i;
                    yB = j;
                    map[i][j] = 'B';
                }
            }
        }
        book[xA][yA] = 1;
        dfs(xA,yA,'0', 0);
        System.out.println(stepMin);
    }
    public static void dfs(int x, int y, char ch, int step) {
        if(x == xB && y == yB) {
            if(stepMin > step) {
                stepMin = step;
            }
            return ;
        }
        int tx, ty;
        for(int i = 0; i < 4; i++) {
            tx  = x + next[i][0];
            ty = y + next[i][1];
            if(tx < 0 || ty < 0 || tx >= n || ty >= n) {
                continue;
            }
            if(map[tx][ty] != ch && book[tx][ty] == 0 ){
                book[tx][ty] = 1;
                dfs(tx, ty, map[tx][ty], step + 1);
                book[tx][ty] = 0;
            }
        }
    }
}



5.标题:表格计算
某次无聊中, atm 发现了一个很老的程序。这个程序的功能类似于 Excel ,它对一个表格进行操作。
不妨设表格有 n 行,每行有 m 个格子。
每个格子的内容可以是一个正整数,也可以是一个公式。
公式包括三种:
1. SUM(x1,y1:x2,y2) 表示求左上角是第 x1 行第 y1 个格子,右下角是第 x2 行第 y2 个格子这个矩形内所有格子的值的和。
2. AVG(x1,y1:x2,y2) 表示求左上角是第 x1 行第 y1 个格子,右下角是第 x2 行第 y2 个格子这个矩形内所有格子的值的平均数。
3. STD(x1,y1:x2,y2) 表示求左上角是第 x1 行第 y1 个格子,右下角是第 x2 行第 y2 个格子这个矩形内所有格子的值的标准差。
标准差即为方差的平方根。
方差就是:每个数据与平均值的差的平方的平均值,用来衡量单个数据离开平均数的程度。
公式都不会出现嵌套。
如果这个格子内是一个数,则这个格子的值等于这个数,否则这个格子的值等于格子公式求值结果。
输入这个表格后,程序会输出每个格子的值。atm 觉得这个程序很好玩,他也想实现一下这个程序。
「输入格式」
第一行两个数 n, m 。
接下来 n 行输入一个表格。每行 m 个由空格隔开的字符串,分别表示对应格子的内容。
输入保证不会出现循环依赖的情况,即不会出现两个格子 a 和 b 使得 a 的值依赖 b 的值且 b 的值依赖 a 的值。
「输出格式」
输出一个表格,共 n 行,每行 m 个保留两位小数的实数。
数据保证不会有格子的值超过 1e6 。
「样例输入」
3 2
1 SUM(2,1:3,1)
2 AVG(1,1:1,2)
SUM(1,1:2,1) STD(1,1:2,2)
「样例输出」
1.00 5.00
2.00 3.00
3.00 1.48
「数据范围」
对于 30% 的数据,满足: n, m <= 5
对于 100% 的数据,满足: n, m <= 50
资源约定:
峰值内存消耗(含虚拟机) < 512M
CPU消耗  < 2000ms

  1. import java.util.Map;  
  2. import java.util.Scanner;  
  3.   
  4. //数据不大,每次循环遍历数组处理数据,直到数据的数据都为数字为止。  
  5. public class Main{  
  6.     public static void main(String[] args) {  
  7.         Scanner scanner = new Scanner(System.in);  
  8.         int n = scanner.nextInt();  
  9.         int m = scanner.nextInt();  
  10.         scanner.nextLine();  
  11.         String [][]s = new String[n][m];  
  12.         for(int i = 0; i < n; i++) {  
  13.             String string = scanner.nextLine();  
  14.             s[i] = string.split(“ ”);  
  15.         }  
  16.         boolean add;  
  17.         do{  
  18.             add = false;  
  19.             for(int i = 0; i < n; i++) {  
  20.                 for(int j = 0; j < m; j++) {  
  21.                       
  22.                     if(s[i][j].indexOf(“SUM”) != -1){  
  23.                         String str[] = s[i][j].split(“ |,|:|,| | , | : | , | ”);  
  24.                         int x1 = Integer.valueOf(str[1]);  
  25.                         int y1 = Integer.valueOf(str[2]);  
  26.                         int x2 = Integer.valueOf(str[3]);  
  27.                         int y2 = Integer.valueOf(str[4]);  
  28.                         //System.out.println(x1 +” ” + y1 + ” ” + x2 + ” ” + y2);  
  29.                         float sum = 0;  
  30.                         for(; x1 <= x2; x1++) {  
  31.                             for(int y = y1;y <= y2; y++) {  
  32.                                 if(s[x1-1][y-1].indexOf(“SUM”) != -1||  
  33.                                    s[x1-1][y-1].indexOf(“AVG”) != -1||  
  34.                                    s[x1-1][y-1].indexOf(“STD”) != -1){  
  35.                                     add = true;  
  36.                                       
  37.                                     x1 = x2+1;  
  38.                                     break;  
  39.                                 }else {  
  40.                                     sum += Float.valueOf(s[x1-1][y-1]);  
  41.                                 }  
  42.                             }     
  43.                         }  
  44.                       
  45.                         if(x1 != x2 + 2){  
  46.                             s[i][j] = sum + ”“;  
  47.                         }  
  48.                       
  49.                     }else if(s[i][j].indexOf(“AVG”) != -1) {  
  50.                         String str[] = s[i][j].split(“ |,|:|,| | , | : | , | ”);  
  51.                         int x1 = Integer.valueOf(str[1]);  
  52.                         int y1 = Integer.valueOf(str[2]);  
  53.                         int x2 = Integer.valueOf(str[3]);  
  54.                         int y2 = Integer.valueOf(str[4]);  
  55.                         float sum = 0;  
  56.                         int num = (x2-x1+1) * (y2-y1+1);  
  57.                         for(; x1 <= x2; x1++) {  
  58.                             for(int y = y1;y <= y2; y++) {  
  59.                                 if(s[x1-1][y-1].indexOf(“SUM”) != -1||  
  60.                                    s[x1-1][y-1].indexOf(“AVG”) != -1||  
  61.                                    s[x1-1][y-1].indexOf(“STD”) != -1){  
  62.                                     add = true;  
  63.                                     x1 = x2+1;  
  64.                                     break;  
  65.                                 }else {  
  66.                                     sum += Float.valueOf(s[x1-1][y-1]);  
  67.                                 }  
  68.                             }  
  69.                         }  
  70.                         if(x1 != x2 + 2){  
  71.                             s[i][j] = sum/num + ”“;  
  72.                         }  
  73.                     }else if(s[i][j].indexOf(“STD”) != -1) {  
  74.                         String str[] = s[i][j].split(“ |,|:|,| | , | : | , | ”);  
  75.                         int x1 = Integer.valueOf(str[1]);  
  76.                         int y1 = Integer.valueOf(str[2]);  
  77.                         int x2 = Integer.valueOf(str[3]);  
  78.                         int y2 = Integer.valueOf(str[4]);  
  79.                         float sum = 0;  
  80.                         int num = (x2-x1+1) * (y2-y1+1);  
  81.                         for(; x1 <= x2; x1++) {  
  82.                             for(int yy1;y <= y2; y++) {  
  83.                                 if(s[x1-1][y-1].indexOf(“SUM”) != -1||  
  84.                                    s[x1-1][y-1].indexOf(“AVG”) != -1||  
  85.                                    s[x1-1][y-1].indexOf(“STD”) != -1){  
  86.                                     add = true;  
  87.                                     x1 = x2+1;  
  88.                                     break;  
  89.                                 }else {  
  90.                                     sum += Float.valueOf(s[x1-1][y-1]);  
  91.                                 }  
  92.                             }  
  93.                         }  
  94.                         float avg = sum/num;  
  95.                         if(x1 != x2 + 2){  
  96.                             sum = 0;  
  97.                             x1 = Integer.valueOf(str[1]);   
  98.                               
  99.                             for(;x1 <= x2; x1++){  
  100.                                 for(int y = y1;y <= y2; y++){  
  101.                                     Float tempFloat = (Float.valueOf(s[x1-1][y-1]) - avg)* (Float.valueOf(s[x1-1][y-1]) - avg);   
  102.                                     sum += tempFloat;  
  103.                                 }  
  104.                             }  
  105.                             avg = sum/num;  
  106.                             avg = (float)Math.sqrt(avg);  
  107.                             s[i][j] = avg + ”“;  
  108.                         }  
  109.                     }  
  110.                 }  
  111.             }  
  112.               
  113.         }while(add);  
  114.           
  115.         for(int i = 0; i < n; i++) {  
  116.             for(int j = 0; j < m; j++) {  
  117.                 System.out.print(String.format(“%.2f”, Float.valueOf(s[i][j])));  
  118.                 if(j != m-1) {  
  119.                     System.out.print(“ ”);  
  120.                 }else {  
  121.                     System.out.println();  
  122.                 }  
  123.             }  
  124.         }  
  125.     }  
  126. }  
import java.util.Map;
import java.util.Scanner;

//数据不大,每次循环遍历数组处理数据,直到数据的数据都为数字为止。
public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        scanner.nextLine();
        String [][]s = new String[n][m];
        for(int i = 0; i < n; i++) {
            String string = scanner.nextLine();
            s[i] = string.split(" ");
        }
        boolean add;
        do{
            add = false;
            for(int i = 0; i < n; i++) {
                for(int j = 0; j < m; j++) {

                    if(s[i][j].indexOf("SUM") != -1){
                        String str[] = s[i][j].split("\\(|,|:|,|\\)");
                        int x1 = Integer.valueOf(str[1]);
                        int y1 = Integer.valueOf(str[2]);
                        int x2 = Integer.valueOf(str[3]);
                        int y2 = Integer.valueOf(str[4]);
                        //System.out.println(x1 +" " + y1 + " " + x2 + " " + y2);
                        float sum = 0;
                        for(; x1 <= x2; x1++) {
                            for(int y = y1;y <= y2; y++) {
                                if(s[x1-1][y-1].indexOf("SUM") != -1||
                                   s[x1-1][y-1].indexOf("AVG") != -1||
                                   s[x1-1][y-1].indexOf("STD") != -1){
                                    add = true;

                                    x1 = x2+1;
                                    break;
                                }else {
                                    sum += Float.valueOf(s[x1-1][y-1]);
                                }
                            }   
                        }

                        if(x1 != x2 + 2){
                            s[i][j] = sum + "";
                        }

                    }else if(s[i][j].indexOf("AVG") != -1) {
                        String str[] = s[i][j].split("\\(|,|:|,|\\)");
                        int x1 = Integer.valueOf(str[1]);
                        int y1 = Integer.valueOf(str[2]);
                        int x2 = Integer.valueOf(str[3]);
                        int y2 = Integer.valueOf(str[4]);
                        float sum = 0;
                        int num = (x2-x1+1) * (y2-y1+1);
                        for(; x1 <= x2; x1++) {
                            for(int y = y1;y <= y2; y++) {
                                if(s[x1-1][y-1].indexOf("SUM") != -1||
                                   s[x1-1][y-1].indexOf("AVG") != -1||
                                   s[x1-1][y-1].indexOf("STD") != -1){
                                    add = true;
                                    x1 = x2+1;
                                    break;
                                }else {
                                    sum += Float.valueOf(s[x1-1][y-1]);
                                }
                            }
                        }
                        if(x1 != x2 + 2){
                            s[i][j] = sum/num + "";
                        }
                    }else if(s[i][j].indexOf("STD") != -1) {
                        String str[] = s[i][j].split("\\(|,|:|,|\\)");
                        int x1 = Integer.valueOf(str[1]);
                        int y1 = Integer.valueOf(str[2]);
                        int x2 = Integer.valueOf(str[3]);
                        int y2 = Integer.valueOf(str[4]);
                        float sum = 0;
                        int num = (x2-x1+1) * (y2-y1+1);
                        for(; x1 <= x2; x1++) {
                            for(int y= y1;y <= y2; y++) {
                                if(s[x1-1][y-1].indexOf("SUM") != -1||
                                   s[x1-1][y-1].indexOf("AVG") != -1||
                                   s[x1-1][y-1].indexOf("STD") != -1){
                                    add = true;
                                    x1 = x2+1;
                                    break;
                                }else {
                                    sum += Float.valueOf(s[x1-1][y-1]);
                                }
                            }
                        }
                        float avg = sum/num;
                        if(x1 != x2 + 2){
                            sum = 0;
                            x1 = Integer.valueOf(str[1]); 

                            for(;x1 <= x2; x1++){
                                for(int y = y1;y <= y2; y++){
                                    Float tempFloat = (Float.valueOf(s[x1-1][y-1]) - avg)* (Float.valueOf(s[x1-1][y-1]) - avg); 
                                    sum += tempFloat;
                                }
                            }
                            avg = sum/num;
                            avg = (float)Math.sqrt(avg);
                            s[i][j] = avg + "";
                        }
                    }
                }
            }

        }while(add);

        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                System.out.print(String.format("%.2f", Float.valueOf(s[i][j])));
                if(j != m-1) {
                    System.out.print(" ");
                }else {
                    System.out.println();
                }
            }
        }
    }
}




6.标题:铺瓷砖

为了让蓝桥杯竞赛更顺利的进行,主办方决定给竞赛的机房重新铺放瓷砖。机房可以看成一个n*m的矩形,而这次使用的瓷砖比较特别,有两种形状,如【图1.png】所示。在铺放瓷砖时,可以旋转。

    

主办方想知道,如果使用这两种瓷砖把机房铺满,有多少种方案。
【输入格式】
输入的第一行包含两个整数,分别表示机房两个方向的长度。
【输出格式】
输出一个整数,表示可行的方案数。这个数可能很大,请输出这个数除以65521的余数。
【样例输入1】
4 4
【样例输出1】
2
【样例说明1】
这两种方案如下【图2.png】所示:
 
【样例输入2】
2 6
【样例输出2】
4
【数据规模与约定】
对于20%的数据,1<=n, m<=5。
对于50%的数据,1<=n<=100,1<=m<=5。
对于100%的数据,1<=n<=10^15,1<=m<=6。
 资源约定:
峰值内存消耗(含虚拟机) < 512M
CPU消耗  < 8000ms









            </div>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值