> 文档中心 > 【天梯赛】2020年真题(L1)

【天梯赛】2020年真题(L1)

🍀【天梯赛】2020年真题(L1)

    • 🍁L1-065 嫑废话上代码 (5 分)
    • 🌺L1-066 猫是液体 (5 分)
      • 题目链接
      • Java题解
    • 🌳L1-067 洛希极限 (10 分)
      • 题目链接
      • Java题解
    • 🌼L1-068 调和平均 (10 分)
      • 题目链接
      • Java题解
    • 🌷L1-069 胎压监测 (15 分)
      • 题目链接
      • Java题解
    • 🥀L1-070 吃火锅 (15 分)
      • 题目链接
      • Java题解
    • 🌿L1-071 前世档案 (20 分)
      • 题目链接
      • Java题解
    • 🌾L1-072 刮刮彩票 (20 分)
      • 题目链接
      • Java题解

)

🍁L1-065 嫑废话上代码 (5 分)

题目链接

题目详情 - L1-065 嫑废话上代码 (5 分) (pintia.cn)

Java题解

public class Main {public static void main(String[] args) {System.out.println("Talk is cheap. Show me the code.");}}

🌺L1-066 猫是液体 (5 分)

题目链接

题目详情 - L1-066 猫是液体 (5 分) (pintia.cn)

Java题解

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner=new Scanner(System.in);int a=scanner.nextInt();int b=scanner.nextInt();int c=scanner.nextInt();System.out.println(a*b*c);}}

🌳L1-067 洛希极限 (10 分)

题目链接

题目详情 - L1-067 洛希极限 (10 分) (pintia.cn)

Java题解

import java.util.Scanner;public class Main {public static void main(String[] args) {// TODO Auto-generated method stubScanner scanner=new Scanner(System.in);float r=scanner.nextFloat();int flag=scanner.nextInt();float R=scanner.nextFloat();float ans=0;if(flag==0) {ans=(float) (r* 2.455);}else {ans=(float) (r*1.26);}System.out.printf("%.2f ", ans);if(ans>=R) {System.out.println("T_T");}else {System.out.println("^_^");}scanner.close();}}

🌼L1-068 调和平均 (10 分)

题目链接

题目详情 - L1-068 调和平均 (10 分) (pintia.cn)

Java题解

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner=new Scanner(System.in);int n;float a;float ans=0f;while(scanner.hasNext()) {n=scanner.nextInt();for(int i=0;i<n;++i) {a=scanner.nextFloat();ans+=(float)(1.0/a);}ans=ans/n;ans=(float)(1/ans);System.out.printf("%.2f\n", ans);}scanner.close();}}

🌷L1-069 胎压监测 (15 分)

题目链接

题目详情 - L1-069 胎压监测 (15 分) (pintia.cn)

Java题解

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner=new Scanner(System.in);int []num=new int[4];int max=0,index=0,min=0,x,cnt=0;;for(int i=0;i<4;++i) {num[i]=scanner.nextInt();if(num[i]>max) {max=num[i];}}min=scanner.nextInt();x=scanner.nextInt();int []sub=new int[4];for(int i=0;i<4;++i) {sub[i]=Math.abs(num[i]-max);if(sub[i]>x||num[i]<min) {cnt++;index=i;}}if(cnt==0) {System.out.println("Normal");}else if(cnt==1) {System.out.println("Warning: please check #"+(index+1)+"!");}else {System.out.println("Warning: please check all the tires!");}scanner.close();}}

🥀L1-070 吃火锅 (15 分)

题目链接

题目详情 - L1-070 吃火锅 (15 分) (pintia.cn)

Java题解

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner =new Scanner(System.in);String string=scanner.nextLine();boolean flag=false;int cnt=0,index=0,ans=0;while(!string.equals(".")) {cnt++;if(string.contains("chi1 huo3 guo1")) {ans++;if(flag==false) {index=cnt;flag=true;}}//System.out.println(string);string=scanner.nextLine();}System.out.println(cnt);if(ans!=0) {System.out.println(index+" "+ans);}else {System.out.println("-_-#");}scanner.close();}}

🌿L1-071 前世档案 (20 分)

题目链接

题目详情 - L1-071 前世档案 (20 分) (pintia.cn)

Java题解

一开始看到的是树,立马排除了,L1不可能考数据结构;

我又看好像有点像全排列,也立马否定了,全排列的数据是各不相同的,我排之前还要考虑顺序,处理反而麻烦了;

最后想到y,n,不就对应0和1吗??!!

yyy:000==0

yyn:001==1

yny:010==2

所以我们只需要将y用0替换

将n用1替换

最后将字符串以基数为2的形式转为整数,其实就是将二进制转为十进制

int k=Integer.parseInt(strings[i],2);

我才知道Integer.parseInt(strings[i],2);后还可以指定一个参数,看来又得好好看看API了

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner=new Scanner(System.in);int n,m;n=scanner.nextInt();m=scanner.nextInt();scanner.nextLine();String []strings=new String[m];for(int i=0;i<m;++i) {strings[i]=scanner.nextLine();strings[i]=strings[i].replace('y', '0');strings[i]=strings[i].replace('n', '1');//System.out.println(strings[i]);}for(int i=0;i<m;++i) {//System.out.println(strings[i]);int k=Integer.parseInt(strings[i],2);System.out.println(k+1);}scanner.close();}}

🌾L1-072 刮刮彩票 (20 分)

题目链接

题目详情 - L1-072 刮刮彩票 (20 分) (pintia.cn)

Java题解

这道题就是模拟,处理好输入输出,以及8个方向的计算即可,不过我对java运用的不是很熟练,代码写的很繁琐

处理输入:

  1. 一个3*3的数组储存彩票的数值

  2. 3个要刮的位置有x(横坐标),y(纵坐标),w(权值)三个信息要储存,所以我封装成一个类

  3. 代表方向的一个数字

其中一个值得注意的点是,储存彩票信息的数组中的0代表的不是权值0,所以我们要找到彩票中缺了哪一个数,并将对应位置的0用这个数替换,所以我在录入彩票各位置的权值时就做累加,存放在cot变量中,最终用45-cot得到的就是0位置的权值

最终对于8个方向的选择,计算总权值,我写的有些繁琐,可以再套一个循环简化,欢迎评论大家改进代码

import java.util.Scanner;//3个要刮的位置有x(横坐标),y(纵坐标),w(权值)三个信息要储存,所以我封装成一个类class Q{int x;int y;int w;}public class Main {public static void main(String[] args) {Scanner scanner=new Scanner(System.in);int mon[]= {0,0,0,0,0,0,10000,36,720,360,80,252,108,72,54,180,72,180,119,36,306,1080,144,1800,3600}; //储存彩票的信息int [][]board=new int[3][3];Q q1=new Q();Q q2=new Q();Q q3=new Q(); //drt代表方向int drt; int ans=0; //在录入彩票各位置的权值时就做累加,存放在cot变量中int cot=0;for(int i=0;i<3;++i) {for(int j=0;j<3;++j) {board[i][j]=scanner.nextInt();cot += board[i][j];}}  //用45-cot得到的就是0位置的权值for(int i=0;i<3;++i) {for(int j=0;j<3;++j) {if(board[i][j]==0) {board[i][j]=45-cot;}}} //录入刮的位置的信息q1.x=scanner.nextInt();q1.y=scanner.nextInt();q1.w=board[q1.x-1][q1.y-1];q2.x=scanner.nextInt();q2.y=scanner.nextInt();q2.w=board[q2.x-1][q2.y-1];q3.x=scanner.nextInt();q3.y=scanner.nextInt();q3.w=board[q3.x-1][q3.y-1]; //录入选取的方向drt=scanner.nextInt(); switch (drt) {case 1:{for(int j=0;j<3;++j) {ans+=board[0][j];}}break;case 2:{for(int j=0;j<3;++j) {ans+=board[1][j];}}break;case 3:{for(int j=0;j<3;++j) {ans+=board[2][j];}}break;case 4:{for(int i=0;i<3;++i) {ans+=board[i][0];}}break;case 5:{for(int i=0;i<3;++i) {ans+=board[i][1];}}break;case 6:{for(int i=0;i<3;++i) {ans+=board[i][2];}}break;case 7:{for(int i=0;i<3;++i) {ans+=board[i][i];}}break;case 8:{for(int i=0;i<3;++i) {ans+=board[i][2-i];}}break;default:break;}System.out.println(q1.w);System.out.println(q2.w);System.out.println(q3.w);System.out.println(mon[ans]);}}