牛客小白月赛1

总链接(点击进入)

A 水题1

变换了形式的e、我直接是调用java的函数库中的E、写的、(Math.E)、很简单的、

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigDecimal;

public class A {
    static final long MAXN = 2000000000;
    public static void main(String[] args) throws IOException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        double a;
        int x, y, z;
        int T;
        in.nextToken(); T = (int)in.nval;
        while(T-- != 0){
            double tmp;
            in.nextToken(); x = (int)in.nval;
            in.nextToken(); y = (int)in.nval;
            in.nextToken(); z = (int)in.nval;
            a = Math.pow(Math.E, x) * y;
            BigDecimal bd = new BigDecimal(a).setScale(z, BigDecimal.ROUND_HALF_DOWN); // java大数的精度处理方法、
            out.println(bd);
/*            if(z == 1){  // 这个判断这道题目可以通过、下一道题目卡在了 98、、、毒瘤、、、
                out.printf("%.1f\n", a);
            }else if(z == 2){
                out.printf("%.2f\n", a);
            }else if(z == 3){
                out.printf("%.3f\n", a);
            }else if(z == 4){
                out.printf("%.4f\n", a);
            }else if(z == 5){
                out.printf("%.5f\n", a);
            }*/
            out.flush();
        }
    }
    
}

B、水题2

一样的是关于e精度的问题、

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigDecimal;

public class B {
    
    public static void main(String[] args) throws IOException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int T;
        double x, y;
        int z;
        in.nextToken(); T = (int)in.nval;
        while(T-- != 0){
            in.nextToken(); x = in.nval;
            in.nextToken(); y = in.nval;
            in.nextToken(); z = (int)in.nval;
            
            double a = Math.pow(x, Math.E) / y;
            BigDecimal bd = new BigDecimal(a).setScale(z, BigDecimal.ROUND_HALF_DOWN);
            out.println(bd);

/*            if(z == 1){  // 毒瘤、   卡 98  
                out.printf("%.1f\n", a);
            }else if(z == 2){
                out.printf("%.2f\n", a);
            }else if(z == 3){
                out.printf("%.3f\n", a);
            }else if(z == 4){
                out.printf("%.4f\n", a);
            }else if(z == 5){
                out.printf("%.5f\n", a);
            }*/
            out.flush();
        }
    }
}
C:分元宵

(补上补上先放放、)


D:多项式乘法

开两个大小为(最高系数 +1)的一维数组、用来存放项为0 -> n的系数、然后在另外开一个数组、大小为两个最高项相加在加1

两个for循环、i * j 为 [i + j]的系数、复杂度为, O(n * m)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class D {
    static final int MAXN = 1005;
    static int [] a = new int [MAXN];
    static int [] x = new int [505];
    static int [] y = new int [505];
    public static void main(String[] args) throws IOException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n, m;
        in.nextToken(); n = (int)in.nval;
        in.nextToken(); m = (int)in.nval;
        int tmp;  // 两个存系数、、
        for(int i = 0; i <= n; i++){  
            in.nextToken(); tmp = (int)in.nval;
            x[i] = tmp;
        }
        
        for(int i = 0; i <= m; i++){
            in.nextToken(); tmp = (int)in.nval;
            y[i] = tmp;
        }
        
        int num = n + m + 1;
        int [] arr = new int [num];
        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= m; j++){
                arr[i + j] += x[i] * y[j];
            }
        }
        for(int i = 0; i < num; i++){
            if(i != num - 1){
                out.print(arr[i] + " ");
            }else{
                out.println(arr[i]);
            }
        }
        out.flush();
    }
}

E:圆与三角形

emmm暂时不会化简、注意精度输出即可、代码如下:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigDecimal;
import java.text.DecimalFormat;

public class E {
    
    public static void main(String[] args) throws IOException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken(); double a = in.nval;
        a += 1;
        BigDecimal bd = new BigDecimal(a).setScale(2, BigDecimal.ROUND_HALF_DOWN);
        out.println(bd);
//        DecimalFormat df = new DecimalFormat(".00");
//        String s = df.format(a);
//        out.println(s);
        out.flush();
    }
}

F:三视图

开三个二维数组、分别代表这正视图、左视图、以及俯视图、

先全部初始化为‘.’,然后将出现的小盒子的坐标添加表示在相应的坐标系中即可、(需要注意的是、坐标从1开始的、若从1开始,数组可以开的略微大一点)、在输入的格式中、正视图、和左视图、都是以y轴的长度为第一个for循环(i)、所以、y的长度为一维、(前面存储的时候也需要注意啦)、x、z为第二个for循环(j)、这里我们是从上往下输出的、显示好、所以,i是从大的往小的循环、同理、俯视图、第一个for循环是z(i)、第二个是x(j)、

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class F {
    static final int MAXN = 1005;
    static char [][] xy = new char [MAXN][MAXN]; // 存正视图、、
    static char [][] yz = new char [MAXN][MAXN]; // 存左视图、、
    static char [][] zx = new char [MAXN][MAXN]; // 存俯视图、、
    public static void main(String[] args) throws IOException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        Init();
        int a, b, c, d;
        in.nextToken(); a = (int)in.nval;   // x轴的大小、
        in.nextToken(); b = (int)in.nval;   // y轴的大小、
        in.nextToken(); c = (int)in.nval;   // z轴的大小、
        in.nextToken(); d = (int)in.nval;   // 立方体的个数、、
        
        int x, y , z;  // 分别用来输入 x , y , z 的坐标、、
        for(int i = 0; i < d; i++){  //  输入分解到各个坐标上、、
            in.nextToken(); x = (int)in.nval;
            in.nextToken(); y = (int)in.nval;
            in.nextToken(); z = (int)in.nval;
            xy[y][x] = 'x';  // 注意遍历输出的时候、  第一个的是为 y 轴 、 第二个是的x轴、!!!
            yz[y][z] = 'x';
            zx[z][x] = 'x';
//            out.println("输入一个小方块成功、、" + x + " " + y + " " + z);
        }        

        for(int i = 1; i <= b; i++){ // a  x 轴长度、 c z轴长度、、
            for(int j = 1; j <= a; j++){
                out.print(xy[b - i + 1][j]); // 这个一行的输出了、
            }
            out.print(" ");
            for(int j = 1; j <= c; j++){
                out.print(yz[b - i + 1][j]);
            }
            out.println();
        }
        out.println();
        for(int i = 1; i <= c; i++){
            for(int j = 1; j <= a; j++){
                out.print(zx[i][j]);
            }
            out.println();
        }
        out.flush();
    }
    
    private static void Init(){
        for(int i = 0; i < MAXN; i++){
            for(int j = 0; j < MAXN; j++){
                xy[i][j] = '.';
                yz[i][j] = '.';
                zx[i][j] = '.';
            }
        }
    }
}

G:あなたの蛙は旅⽴っています

(未写、应该会补上、)


H:写真がとどいています! 

五线谱、(五条线、夹着四个空白) 用行为9的数组表示、二维的大小为输入的大小、

这个需要一点其他的知识、(Acmer真的很累、)、我们判断每一列、那个小o在那一行就晓得这一列代表的是什么音符了、

(这里横纵坐标交换无所谓、遍历的大小还是一样的、)(可以稍微的优化一下、出现‘|’break停止循环即可、(小的为一重循环))

import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        char [][] music = new char[9][];
        char [] c = new char[5005];
        char a[] = "FEDCBAGFE".toCharArray();
        int n = input.nextInt();
        for(int i = 0; i < 9; i++){
            music[i] = input.next().toCharArray();
        }
        for(int j = 0; j < 9; j++){ // 纵坐标、、
            for(int i = 0; i < n; i++){  // 横坐标、、
                if(music[j][i] == 'o'){
                    c[i] = a[j];
                }else if(music[j][i] == '|'){
                    c[i] = '|';
                }
            }
        }
        for(int i = 0; i < n; i++){
            System.out.print(c[i]);
        }
        System.out.println("");
        
    }
}

I:あなたの蛙が帰っています! 

这个好像叫做卡特兰数、什么什么的、(待续)

J:おみやげをまらいました! 

类始于猜拳的比较字符串输出、

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class J {
    
    public static void main(String[] args) throws IOException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        String s1, s2, s3;
        in.nextToken(); s1 = in.sval;
        in.nextToken(); s2 = in.sval;
        
        in.nextToken(); s2 = in.sval;
        in.nextToken(); s3 = in.sval;
        
        in.nextToken(); s3 = in.sval;
        in.nextToken(); s1 = in.sval;
        
        in.nextToken(); int N = (int)in.nval;
        while(N-- != 0){
            in.nextToken(); String tmp = in.sval;
            if(tmp.equals(s1)){
                out.println(s3);
            }else if(tmp.equals(s2)){
                out.println(s1);
            }else if(tmp.equals(s3)){
                out.println(s2);
            }else{
                out.println("Fake");
            }
            out.flush();
        }
        
    }
            
}

你可能感兴趣的:(ACMer)