目录
真正击垮你的
从来都不是别人的非议,而是你对自己怀疑
你跑的慢,耳边都是闲言碎语
你跑的快,耳边就只有风声
若想得到这世间最好的东西
先得让世界看到最好的你
A:9数算式
因为个人写的比较笨,所以各位看官就当看个过场,千万别学笨怂这种笨笨的写法,会被骂的(呜
答案: 1625
package 蓝桥冲刺31天A.第四天;
import java.io.*;
/**
* @ClassName 九数算式
* @Description TODO
* @Author 小怂很怂
* @Date 2023/3/6 21:41
* @Version 1.0
**/
public class 九数算式 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StreamTokenizer st = new StreamTokenizer(br);
static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
static int []arr={1,2,3,4,5,6,7,8,9};
static int count=0;
public static void main(String[] args) throws Exception {
dfs(0);
pw.println(count);
pw.flush();
}
public static void dfs(int step){
if (step==9){
check();
return;
}
for (int i=step;i<arr.length;i++){
swap(i,step);
dfs(step+1);
swap(i,step);
}
}
public static void swap(int i,int j){
int t=arr[i];
arr[i]=arr[j];
arr[j]=t;
}
public static void check() {
int a=arr[0]*(arr[1]*10000000+arr[2]*1000000+arr[3]*100000+arr[4]*10000+arr[5]*1000+arr[6]*100+arr[7]*10+arr[8]);
int b=(arr[0]*10+arr[1])*(arr[2]*1000000+arr[3]*100000+arr[4]*10000+arr[5]*1000+arr[6]*100+arr[7]*10+arr[8]);
int c=(arr[0]*100+arr[1]*10+arr[2])*(arr[3]*100000+arr[4]*10000+arr[5]*1000+arr[6]*100+arr[7]*10+arr[8]);
int d=(arr[0]*1000+arr[1]*100+arr[2]*10+arr[3])*(arr[4]*10000+arr[5]*1000+arr[6]*100+arr[7]*10+arr[8]);
int [][]brr=new int[4][10];
while (a!=0){
brr[0][a%10]++;
a/=10;
}
while (b!=0){
brr[1][b%10]++;
b/=10;
}
while (c!=0){
brr[2][c%10]++;
c/=10;
}
while (d!=0){
brr[3][d%10]++;
d/=10;
}
for (int i=0;i<4;i++){
int t=0;
for (int j=1;j<10;j++){
if (brr[i][j]!=1){
t=1;
break;
}
}
if (t==0) count++;
}
}
public static int nextInt() throws Exception {//int型
st.nextToken();
return (int) st.nval;
}
public static long nextLong() throws Exception {//long型
st.nextToken();
return (long) st.nval;
}
}
B:山
这题写的方法比上面那题还要笨,就不放出来让各位看官笑话了(呜呜呜
答案:3138
C:最少刷题数
我们需要找到一个中间值,即当达到这个值的时候,会满足比这个值大的人数<比这个值小的人数,所以我们选择先对原数组排序,然后取中间值,偶数向上取整,因为同一个数可能存在多个,所以通过遍历找到比该值多的人数与比该值少的人数,剩下的看代码啦,讲的不是很清楚,评论问
package 蓝桥冲刺31天A.第四天;
import java.io.*;
import java.util.Arrays;
/**
* @ClassName 最少刷题数
* @Description TODO
* @Author 小怂很怂
* @Date 2023/3/6 22:35
* @Version 1.0
**/
public class 最少刷题数 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StreamTokenizer st = new StreamTokenizer(br);
static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws Exception {
int n=nextInt();
int []arr=new int[n+1];
int []brr=new int[n+1];
for (int i=1;i<=n;i++){
arr[i]=nextInt();
brr[i]=arr[i];
}
Arrays.sort(arr);
int x=arr[n/2+1];
int min=0,max=0;
for (int i=1;i<=n;i++){
if (arr[i]<x) min++;//少的人数
else if (arr[i]>x) max++;//多的人数
}
int s=0;
if (min<max) x=x+1;
else if (min==max) s=1;//相同要判定是否要刷比这个题多1
for (int i=1;i<=n;i++){
if (s==1&&brr[i]!=x) {
pw.print(Math.max(0, x + 1 - brr[i]) + " ");
}else{
pw.print(Math.max(0, x - brr[i]) + " ");
}
}
pw.flush();
}
public static int nextInt() throws Exception {//int型
st.nextToken();
return (int) st.nval;
}
public static long nextLong() throws Exception {//long型
st.nextToken();
return (long) st.nval;
}
}
D:完全平方数
万分感谢梗佬送来的思路
一个数为完全平方数,那么它的因子一定可以是完全平方数,按照这个原理去进行计算
package 蓝桥冲刺31天A.第四天;
import java.io.*;
import java.math.BigInteger;
import java.util.Arrays;
/**
* @ClassName 完全平方数
* @Description TODO
* @Author 小怂很怂
* @Date 2023/3/6 23:05
* @Version 1.0
**/
public class 完全平方数 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StreamTokenizer st = new StreamTokenizer(br);
static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws Exception {
long n=nextLong();
long x=(long)Math.sqrt(n);
for (int i=2;i<=x;i++){
if (n%((long) i *i)==0){
n/=((long) i *i);
i--;//16这样的存在
}
}
System.out.println(n);
pw.flush();
}
public static int nextInt() throws Exception {//int型
st.nextToken();
return (int) st.nval;
}
public static long nextLong() throws Exception {//long型
st.nextToken();
return (long) st.nval;
}
}