目录
没有暗无天日的绝境,只有甘愿认输的自己;
夜色难免黑凉,但前行必有曙光;如果你瞄准月亮,即使迷失,也是落在了星辰之上。
A:数的分解
签到题,因为确定不能重复,所以可以固定第一个数<第二个数<第三个数
然后对于每一个数进行枚举与判断即可
import java.io.*;
/**
* @ClassName 数的分解
* @Description TODO
* @Author 小怂很怂
* @Date 2023/3/7 22:31
* @Version 1.0
**/
public class Main {
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 s=0;
for (int i=1;i<673;i++){
int b=pd(i,0);
if (b==1) continue;
for (int j=i+1;j<=(2019-i)/2;j++){
int n=pd(j,0);
if (n==1) continue;
int k=2019-i-j;
n=pd(k,0);
if (n==1||k<=j) continue;
s++;
}
}
pw.println(s);
pw.flush();
}
public static int pd(int a,int b){
int x=a,y=b;
while (x!=0){
if (x%10==2||x%10==4){
y=1;
return y;
}
x/=10;
}
return y;
}
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:猜生日
也是一个签到枚举,枚举一下年份和日期,月份固定为6,然后年份乘万+ 600+日期对2012和12取模判断即可,注意输出如果日期小于10要前导0
package 蓝桥冲刺31天A.第五天;
import java.io.*;
/**
* @ClassName 猜生日
* @Description TODO
* @Author 小怂很怂
* @Date 2023/3/7 22:44
* @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 {
for (int i=1900;;i++){
for (int j=1;j<=31;j++){
int s=i*10000+600+j;
if (s % 2012 == 0 && s % 12 == 0){
if (j<10){
pw.println(i+"060"+j);
}else{
pw.println(i+"06"+j);
}
pw.flush();
return;
}
}
}
//必须加
}
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;
}
}
C:成绩统计
对每一个输入的数进行统计,因为是按照百分比四舍五入,所以+0.005;将一个小数变为整数:(int)*100即可
package 蓝桥冲刺31天A.第五天;
import java.io.*;
/**
* @ClassName 成绩统计
* @Description TODO
* @Author 小怂很怂
* @Date 2023/3/7 22:51
* @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();
double s=0,c=0;
int a,b;
int []arr=new int[n];
for (int i=0;i<n;i++){
arr[i]=nextInt();
if (arr[i]>=85){
s++;
c++;
}else if(arr[i]>=60){
c++;
}
}
s=s/n+0.005;
c=c/n+0.005;
a= (int) (s*100);
b=(int)(c*100);
pw.println(b+"%");
pw.println(a+"%");
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:最大和
动态规划,遍历每一个可以走的格子,对该位置保留最大值(数据不大)
import java.io.*;
import java.util.Arrays;
/**
* @ClassName 最大和
* @Description TODO
* @Author 小怂很怂
* @Date 2023/3/7 23:03
* @Version 1.0
**/
public class Main {
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];
for (int i=1;i<=n;i++) arr[i]=nextInt();
int []brr=new int[n+1];
Arrays.fill(brr,Integer.MIN_VALUE);
brr[1]=arr[1];
for (int i=1;i<=n;i++){
int t=pd(n-i);
for (int j=1;j<=t;j++){
if(i+j<=n) brr[j+i]=Math.max(brr[j+i],brr[i]+arr[j+i]);
}
}
pw.println(brr[n]);
pw.flush();
}
public static int pd(int a){
if (a==1) return 1;
if (a%2==0) return 2;
int b= (int) Math.sqrt(a);
for (int i=3;i<=b;i+=2){
if (a%i==0) return i;
}
return a;
}
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;
}
}