A,阶乘求和
令s=1!+2!+3!+.........202320232023!
求s的末尾9位数字
提示:答案首位不能为0
package lanqiao;
public class jiechengqiuhe {
public static void main(String[] args){
long start=1;
String s="202320232023";
long a=Long.parseLong(s);
long sum=0;
long cj=1;
while (start<=a){
cj*=start;
cj%=1000000000;
sum+=cj;
sum%=1000000000;
start++;
if(start>40){
System.out.println(sum);
}
System.out.println(sum);
}
}
}
运行结果:
对此我们可以知道这个数的结果其实已经是确定的,其实呢这个也是蓝桥杯的一个套路,这个数在加到40!的时候后面的数字就已经是00000了所以没必要一直加到202320232023.
B幸运数字
哈沙德数是指在某个固定的进制当中,可以被各位数字之和整除的正整数,例如126是十进制下的一个哈沙德数,因为(126)10mod(1+2+6)=0;126也是8机制下的哈沙德数,同时也是在16机制以及2进制下的哈沙德数,那么在1,2,4,6,8,40,48,72,120,126......。现在想知道2023个哈沙德数是谁
package lanqiao;
public class hasgade {
public static void main(String[] args){
int j=0;
for (int i=1;i<10000000;i++){
if (BaseConversion(i)){
j++;
if (j==2023){
System.out.println(i);
break;
}
}
}
}
public static boolean BaseConversion(int n){
int sum=0;
int x=n;
while (x!=0){
sum+=(x%10);
x/=10;
}
if(n%sum!=0){
return false;
}
sum=0;
x=n;
while (x!=0){
sum+=(x%2);
x/=2;
}
if(n%sum!=0){
return false;
}
sum=0;
x=n;
while (x!=0){
sum+=(x%8);
x/=8;
}
if (n%sum!=0){
return false;
}
sum=0;
x=n;
int[]arr={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
while (x!=0){
sum+=(arr[x%16]);
x/=16;
}
if (n%sum!=0){
return false;
}
return true;
}
}
下面是运行的结果
解题的思路很简单就是单纯的查找就好了唯一要求的是我们要知道如何进行进制之间的转换
C数组分割
小蓝有一个长度为 N 的数组 A = [ A 0 , A 1 , . . . , A N − 1 ] 。现在小蓝想要从 A 对应的数组下标所构成的集合 I = { 0 , 1 , 2 , . . . , N − 1 } 中找出一个子集 R 1 ,那么 R 1在 I 中的补集为 R 2 。记 S 1 = ∑ r ∈ R 1 A r , S 2 = ∑ r ∈ R 2 A r,我们要求 S 1 和 S 2 均为 偶数,请问在这种情况下共有多少代码种不同的 R 1。当 R1 或 R 2 为空集时我们将 S 1 或 S 2 视为 0。
代码如下
package lanqiao;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.stream.StreamSupport;
public class zhaoshuzi {
public static final BigInteger MOD=new BigInteger("1000000007");
public static final BigInteger GAN=new BigInteger("2");
public static void main(String[] args){
Scanner scanner=new Scanner(System.in);
int a=scanner.nextInt();
while (a-->0){
int n= scanner.nextInt();
int x=0;//记录偶数
int y=0;//记录奇数
for (int i=0;i<n;i++){
int b=scanner.nextInt()%2;
if (b==0){
x++;
}else {
y++;
}
}
if(y%2==1){
System.out.println(0);
}
else {
System.out.println(GAN.pow(x+(y==0?0:y-1)).mod(MOD));
}
}
}
}
运行结果
D矩阵总面积
平面上有个两个矩形 R 1 和 R 2 ,它们各边都与坐标轴平行。设 ( x 1 , y 1 ) 和 (x 2 , y 2 ) 依次是 R 1 的左下角和右上角坐标, ( x 3 , y 3 ) 和 ( x 4 , y 4 ) 依次是 R 2 的左下 角和右上角坐标,请你计算 R 1 和 R 2 的总面积是多少?
注意:如果 R 1 和 R 2 有重叠区域,重叠区域的面积只计算一次。
【输入格式】
输入只有一行,包含 8 个整数,依次是: x 1 , y 1 , x 2 , y 2 , x 3 , y 3 , x 4 和 y 4 。
代码如下:
package lanqiao;
import java.util.Scanner;
public class qiumainji {
public static void main(String[] args){
Scanner scanner=new Scanner(System.in);
int x1=scanner.nextInt();
int y1=scanner.nextInt();
int x2=scanner.nextInt();
int y2=scanner.nextInt();
int x3=scanner.nextInt();
int y3=scanner.nextInt();
int x4=scanner.nextInt();
int y4=scanner.nextInt();
long area=(long) (x2-x1)*(y2-y1);
long area1=(long) (x4-x3)*(y4-y3);
long overlapArea=0;
long l=Math.min(x2,x4)-Math.min(x1,x3);
long w=Math.min(y2,y4)-Math.min(y1,y3);
if(l>=0&&w>=0){
overlapArea=l*w;
}
long area2=area+area1-overlapArea;
System.out.println(area2);
}
}
运行结果
E蜗牛
这天,一只蜗牛来到了二维坐标系的原点。 在 x 轴上长有 n 根竹竿。它们平行于 y 轴,底部纵坐标为 0 ,横坐标分别 为 x 1 , x 2 , ..., x n 。竹竿的高度均为无限高,宽度可忽略。蜗牛想要从原点走到第 n 个竹竿的底部也就是坐标 ( x n , 0) 。它只能在 x 轴上或者竹竿上爬行,在 x 轴
上爬行速度为 1 单位每秒;由于受到引力影响,蜗牛在竹竿上向上和向下爬行 的速度分别为 0 . 7 单位每秒和 1 . 3 单位每秒。 为了快速到达目的地,它施展了魔法,在第 i 和 i + 1 根竹竿之间建立了传 送门(0 < i < n ),如果蜗牛位于第 i 根竹竿的高度为 a i 的位置 ( x i , a i ) ,就可以 瞬间到达第 i + 1 根竹竿的高度为 b i +1 的位置 ( x i +1 , b i +1 ), 请计算蜗牛最少需要多少秒才能到达目的地。
代码如下
import java.io.*;
import java.util.*;
public class Main{
static int maxn = 200005,n,m;
static long INF = (long)2e18,ans = 0,mod = (int)1e9+7;
static Scanner sc = new Scanner (System.in);
static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
static StreamTokenizer st =new StreamTokenizer(bf);
static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
public static void main(String[]args) throws IOException{
int T = 1;
//T = Integer.parseInt(S());
while(T-->0) solve();
pw.flush();
}
static final int I() throws IOException {
st.nextToken();
return (int)st.nval;
}
static void solve() throws IOException{
n = I();
long x[] = new long [n+1];
for(int i=1;i<=n;i++) x[i] = I();
int []a = new int [n+1];
int []b = new int [n+1];
for(int i=1;i<n;i++) {
a[i] = I();b[i] = I();
}
double dp[][] = new double[n+1][2];
dp[1][0] = x[1]; //底端最小用时
dp[1][1] = x[1] + a[1] / 0.7; //传送门用时
for(int i=2; i<=n ; i++) {
dp[i][0] = Math.min(dp[i-1][0]+x[i]-x[i-1], dp[i-1][1] + b[i-1]/1.3);
dp[i][1] = Math.min(dp[i][0] + a[i] / 0.7, dp[i-1][1] + ((b[i-1]>a[i])?(b[i-1]-a[i])/1.3: (a[i]-b[i-1])/0.7));
}
pw.printf("%.2f",dp[n][0]);
}
}
谢谢大家的观看,马上2024年的蓝桥杯就要开始预祝大家都能拿到好的成绩。