名企笔试题-棋子翻转、平均年龄、钓鱼比赛、最高分是多少

//棋子翻转
package enterprise;

import java.util.*;

public class Flip {
    public int[][] flipChess(int[][] A, int[][] f) {
            for(int i = 0; i < 3; i++) {
                int m = f[i][0] - 1;
                int n = f[i][1] - 1;
                if((m-1) >= 0) 
                    A[m-1][n] = A[m-1][n] == 0 ? 1 : 0;
                if((m+1) <= 3)  
                    A[m+1][n] = A[m+1][n] == 0 ? 1 : 0;
                if((n-1) >= 0)
                    A[m][n-1] = A[m][n-1] == 0 ? 1 : 0;
                if((n+1) <= 3)
                    A[m][n+1] = A[m][n+1] == 0 ? 1 : 0;
            }
        return A;
    }
}
//平均年龄

package enterprise;

import java.util.Scanner;
public class Main
{
    public static int averageAge(int w, int y, double x, int n)
    {
        double aver_age = y;
        for(int i = 1; i <= n; i++)
        {
            aver_age = (x * 21) +(aver_age + 1)*(1 - x); //在过程中使用double类型,最后再转换为int类型
        }
        return (int)Math.ceil(aver_age);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);//学习Scanner类的用法
        while(sc.hasNext())//当输入有值时,hasNext()一个单词一个单词的取值
        {
            int W = sc.nextInt();//输入int
            int Y = sc.nextInt();
            double x = sc.nextDouble();//输入double
            int N = sc.nextInt();
            System.out.println(averageAge(W,Y,x,N));
        }
    }
}
//钓鱼比赛
package enterprise;

import java.util.Scanner;
public class Fish {
    public static void fish(double[][] p, int n, int m, int x, int y, int t){
        double cc = 1 - Math.pow(1 - p[x][y], t);
        double ssp = 0;
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
                ssp += (p[i][j]/(n*m));
        }
        double ss = 1 - Math.pow(1 - ssp, t);;
        if(cc > ss)
        {
            System.out.println("cc");
            System.out.println(String.format("%.2f", cc));
        }
        else if(cc < ss)
        {
            System.out.println("ss");
            System.out.println(String.format("%.2f", ss));
        }
        else
        {
            System.out.println("equal");
            System.out.println(String.format("%.2f", cc));
        }
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            int m = sc.nextInt();
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            int t = sc.nextInt();
            sc.nextLine(); //把第一行取完,完成换行的目的
            double[][] p = new double[n][m];
            for(int i = 0; i < n; i++)
            {
                String[] s = sc.nextLine().split(" "); //从输入的第二行开始将每一行读到的数字按照空格分开存放在字符串数组s中,这个数组s的大小就是m
                for(int j = 0; j < m; j++)
                {
                    p[i][j] = Double.parseDouble(s[j]);//然后再把每一个字符串强转放到二维数组里面
                }
            }
            fish(p, n, m, x, y, t);
        }

    }
}
//最高分是多少
package enterprise;

import java.util.Scanner;
public class MaxScore {
    public static void maxScore(char c, int left, int right, int[] score) {
        if(c == 'Q'){ //查询最大值
            if(left > right) {int temp = right; right = left; left = temp;}
            int max = score[left - 1];
            for(int i = left; i < right; i++)
            {
                if(score[i] > max)
                max = score[i];
            }
            System.out.println(max);
        }
        else //更新
            score[left-1] = right;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            int n = sc.nextInt(); 
            int m = sc.nextInt();
            sc.nextLine();
            String[] s = sc.nextLine().split(" ");
            int[] score = new int[n];
            for(int i = 0; i < n; i++) {
                score[i] = Integer.parseInt(s[i]);
            }
            char c = ' ';
            int left = 0;
            int right = 0;
            for(int i = 0; i < m; i++) {
                String[] s1 = sc.nextLine().split(" ");
                c = s1[0].charAt(0);
                left = Integer.parseInt(s1[1]);
                right = Integer.parseInt(s1[2]);
                maxScore(c, left, right, score);
            }

        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值