并非正确答案,一个菜鸡随便写的。
签到题,api解决,答案11.
System.out.print(Integer.toBinaryString(2022).length());
直接用日历数,结果138
没考虑越界,有没有问题不知道,这样结果为91329还真是我想太简单,首先float不行,精度不够,并且最后一次在循环中index多加了1,要减去1,这是一个坑,最终答案91380
/*public class Test3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
float index=1;
float sum=0;
while(sum<=12) {
sum+=1/index;
index++;
}
System.out.print(sum+" ");
System.out.print(index);
}
}
*/
public class Test3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
double index=1f;
double sum=0;
while(sum<=12f) {
sum+=1/index;
index++;
}
System.out.print(sum+" ");
System.out.print(index-1);
}
}
还以为要搜索,发现只要比较每一个字母四个方向,直接模拟,结果为349丢人丢到奶奶家,忘记加等号了。。。答案276
public class Test4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="PHQGHUMEAYLNLFDXFIRCVSCXGGBWKFNQDUXWFNFOZVSRTKJPREPGGXRPNRVY" +
"STMWCYSYYCQPEVIKEFFMZNIMKKASVWSRENZKYCXFXTLSGYPSFADPOOEFXZBC" +
"OEJUVPVABOYGPOEYLFPBNPLJVRVIPYAMYEHWQNQRQPMXUJJLOOVAOWUXWHMS" +
"NCBXCOKSFZKVATXDKNLYJYHFIXJSWNKKUFNUXXZRZBMNMGQOOKETLYHNKOAU" +
"GZQRCDDIUTEIOJWAYYZPVSCMPSAJLFVGUBFAAOVLZYLNTRKDCPWSRTESJWHD" +
"IZCOBZCNFWLQIJTVDWVXHRCBLDVGYLWGBUSBMBORXTLHCSMPXOHGMGNKEUFD" +
"XOTOGBGXPEYANFETCUKEPZSHKLJUGGGEKJDQZJENPEVQGXIEPJSRDZJAZUJL" +
"LCHHBFQMKIMWZOBIWYBXDUUNFSKSRSRTEKMQDCYZJEEUHMSRQCOZIJIPFION" +
"EEDDPSZRNAVYMMTATBDZQSOEMUVNPPPSUACBAZUXMHECTHLEGRPUNKDMBPPW" +
"EQTGJOPARMOWZDQYOXYT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LDACLLTEO" +
"JOMONXRQYJZGINRNNZWACXXAEDRWUDXZRFUSEWJTBOXVYNFHKSTCENAUMNDD" +
"XFDMVZCAUTDCCKXAAYDZSXTTOBBGQNGVVPJGOJOGLMKXGBFCPYPCKQCHBDDZ" +
"WRXBZMQRLXVOBTWHXGINFGFRCCLMZNMJUGWWBSQFCIHUBSJOLLMSQSGHMCPH" +
"ELSOTFLBGSFNPCUZSRUPCHYNVZHCPQUGRIWNIQXDFJPWPXFBLKPNPEELFJMT";
char[][] grid=new char[30][60];
int index=0;
for(int i=0;i<30;i++) {
for(int j=0;j<60;j++) {
grid[i][j]=str.charAt(index++);
}
}
int res=0;
int[][] dir= {{0,1},{0,-1},{1,0},{-1,0}};
for(int i=0;i<30;i++) {
for(int j=0;j<60;j++) {
if(i==0||i==29||j==0||j==59) continue;
boolean flag=true;
char c=grid[i][j];
for(int[] arr:dir) {
int newi=arr[0]+i;
int newj=arr[1]+j;
if(grid[newi][newj]<=c) {//和旁边的字母相等也不是山谷,注意等号
flag=false;
break;
}
}
if(flag) res++;
}
}
System.out.print(res);
}
}
子矩阵的问题,蓝桥杯上看到好几次,没搞过,这个要系统练习一下使用的是二维数组的前缀和,学过没用过,这就忘了,复习一下,前缀和主要要结合图形理解,答案为12.
package 第十四届模拟赛;
import java.util.Arrays;
public class Test5 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] grid=new int[100][100];
int[][] sum=new int[100][100];
grid[0][0]=1;
for(int i=0;i<100;i++) {
for(int j=0;j<100;j++) {
if(i==0&&j==0) continue;
if(i==0) {
grid[i][j]=grid[i][j-1]+2;
}
if(i!=0) {
grid[i][j]=grid[i-1][j]+1;
}
}
}
sum[0][0]=1;
for(int i=1;i<100;i++) {//第一列
sum[i][0]=sum[i-1][0]+grid[i][0];
}
for(int j=1;j<100;j++) {//第一行
sum[0][j]=sum[0][j-1]+grid[0][j];
}
for(int i=1;i<100;i++) {
for(int j=1;j<100;j++) {
sum[i][j]=sum[i-1][j]+sum[i][j-1]+grid[i][j]-sum[i-1][j-1];
}
}
int res=Integer.MAX_VALUE;
for(int i=1;i<100;i++) {
for(int j=1;j<100;j++) {
for(int a=99;a>=i;a--) {
for(int b=99;b>=j;b--) {
if(check(i,j,a,b,sum)==2022) {
res=Math.min(res, (a-i+1)*(b-j+1));
}
}
}
}
}
System.out.print(res);
}
private static int check(int i, int j, int a, int b, int[][] sum) {
// TODO Auto-generated method stub
return sum[a][b]-sum[i-1][b]-sum[a][j-1]+sum[i-1][j-1];
}
}
咱也不知道是我想太简单了还是模拟赛就单纯是想教我们怎么考试,直接搞
public class Test6 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
if(b>a) {
System.out.print(b-a);
}
if(b
难度不是很理解,可能是我理解错了,不确定,再看看
public class Test7 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String str=sc.next();
System.out.print(str.replace('a', 'A').replace('e', 'E').replace('i', 'I').replace('o', 'O').replace('u', 'U'));
}
}
被前面的题看蒙了,现在就会模拟写下去了
public class Test8 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int res=0;
String curtime=sc.next();
int curh=Integer.parseInt(curtime.substring(0, 2));
int curm=Integer.parseInt(curtime.substring(3, 5));
int curs=Integer.parseInt(curtime.substring(6, 8));
int curU=sc.nextInt();
int curI=sc.nextInt();
t--;
while(t>0) {
String nowtime=sc.next();
int nowh=Integer.parseInt(nowtime.substring(0, 2));
int nowm=Integer.parseInt(nowtime.substring(3, 5));
int nows=Integer.parseInt(nowtime.substring(6, 8));
int dif=(nowh-curh)*3600+(nowm-curm)*60+(nows-curs);
res+=(curU*curI*dif);
curU=sc.nextInt();
curI=sc.nextInt();
curh=nowh;
curm=nowm;
curs=nows;
t--;
}
System.out.print(res);
}
}
一般比赛后面两个题压根不敢写,看了看题,没啥思路,赶着吃饭,跳过
要最小的字符串,因为都是无限的,所以看前面的字符越小越好,所以主要要解决最小的字符相同的情况,只有一个最小字符就可以确定最小的就是,有相同的就要回溯,看他们跳转过去的字符的大小,还一样就一直向下比,但是有完全一样的情况,这样就会栈溢出,这里用个num记着层数省的炸掉,咱也不知道数据大起来会怎样,随便搞一下
public class Test10 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String str=sc.next();
int[] arr=new int[str.length()];
for(int i=0;i=str.length()) {
return Math.min(i,j);
}
if(str.charAt(arr[soni])>str.charAt(arr[sonj])) {
return j;
}
if(str.charAt(arr[soni])
待答案出来再来修改,仅供参考。