您的位置:首页 > 健康 > 养生 > saas商城系统_苏州企业网站建设制作服务_著名的个人网站_常州网络推广seo

saas商城系统_苏州企业网站建设制作服务_著名的个人网站_常州网络推广seo

2025/4/27 21:54:49 来源:https://blog.csdn.net/qq_30500575/article/details/147025462  浏览:    关键词:saas商城系统_苏州企业网站建设制作服务_著名的个人网站_常州网络推广seo
saas商城系统_苏州企业网站建设制作服务_著名的个人网站_常州网络推广seo

目录

A 报数游戏

B 类斐波那契循环数

C 分布式队列

D 食堂

E 最优分组

F 星际旅行

G LITS 游戏

H 拼十字


今天心血来潮把去年的题目又做了一遍...

本人去年大一 拿的是全省第五进的国赛

而如今的已经是一名 codeforces 1500 分的入门级别的算竞选手了

下周又是蓝桥杯了 想起来后又做了一遍

仅代表个人做题记录

A 报数游戏

import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改public class Main {public static void main(String[] args) {Scanner scan = new Scanner(System.in);System.out.println("2429042904288");//在此输入您的代码...scan.close();}
}

B 类斐波那契循环数

import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改public class Main {public static void main(String[] args) {Scanner scan = new Scanner(System.in);System.out.println("7913837");//在此输入您的代码...scan.close();}
}

C 分布式队列

模拟题

import java.io.*;
import java.math.*;
import java.util.*;public class Main {static Scanner sc = new Scanner(System.in);static final long MOD = (long) (1e9+7);public static void solve() throws IOException {int n=sc.nextInt();// 主节点的数字int ans1=0;// 其余结点int arr[]=new int[n-1];while(sc.hasNext()) {String str=sc.next();if(str.equals("add")) {// 添加int k = sc.nextInt();ans1++;}else if(str.equals("sync")){// 同步int k = sc.nextInt()-1;if(arr[k]<ans1) {arr[k]++;}}else if(str.equals("query")) {// 查询int ans=Integer.MAX_VALUE;for(int j=0;j<n-1;j++) {ans=Math.min(ans, arr[j]);}System.out.println(ans);}}}public static void main(String[] args) throws Exception {int t = 1;
//        t = sc.nextInt();while (t-- > 0) {solve();}}}

D 食堂

数据范围很小啊

把每一种情况都列举出来了

// @github https://github.com/Dddddduo
// @github https://github.com/Dddddduo/acm-java-algorithm
// @github https://github.com/Dddddduo/Dduo-mini-data_structure
import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.*;
import java.time.*;// 食堂// xixi♡西
public class Main {static Scanner sc = new Scanner(System.in);static final int mod = (int) (1e9 + 7);/*** @throws IOException*/private static void solve() throws IOException {// todoint a2=sc.nextInt();int a3=sc.nextInt();int a4=sc.nextInt();int b4=sc.nextInt();int b6=sc.nextInt();int ans = 0;while (b6 > 0) { // 3+3if (a3 >= 2) {b6--;a3 -= 2;ans += 6;} else {break;}}while (b6 > 0) { // 4+2if (a4 > 0 && a2 > 0) {b6--;a4--;a2--;ans += 6;} else {break;}}while (b6 > 0) { // 2+2+2if (a2 >= 3) {b6--;a2 -= 3;ans += 6;} else {break;}}while (b6 > 0) { // 3+2if (a3 > 0 && a2 > 0) {b6--;a3--;a2--;ans += 5;} else {break;}}while (b6 > 0) { // 4if (a4 > 0) {b6--;a4--;ans += 4;} else {break;}}if (b6 > 0 && a2 == 2) { // 2+2ans += 4;b6--;a2 = 0;}if (b6 > 0 && a3 > 0) { // 3ans += 3;b6--;a3 = 0;}if (b6 > 0 && a2 > 0) { // 2ans += 2;a2 = 0;}while (b4 > 0) { // 4if (a4 > 0) {b4--;a4--;ans += 4;} else {break;}}while (b4 > 0) { // 2+2if (a2 >= 2) {b4--;a2 -= 2;ans += 4;} else {break;}}while (b4 > 0) { // 3if (a3 > 0) {b4--;a3--;ans += 3;} else {break;}}if (b4 > 0 && a2 > 0) { // 2ans += 2;}System.out.println(ans);}public static void main(String[] args) throws Exception {int t = 1;t = sc.nextInt();while (t-- > 0) {solve();}}}

E 最优分组

注意用小数进行运算即可

import java.io.*;
import java.math.*;
import java.util.*;public class Main {static Scanner sc = new Scanner(System.in);static final long MOD = (long) (1e9+7);public static void solve() throws IOException {long n=sc.nextLong(); // N只宠物double p=1.0-sc.nextDouble(); // 没被感染的概率if(p==1){System.out.println("0");return;}if(p==0){System.out.println(n);return;}if(n==1){System.out.println("1");return;}double num=n+1; // 消耗的数目long k=0;for(int i=1;i<=n;i++) { // i个人一组 每组恰好有i只宠物double ans = 0; // 消耗的试剂double ans1 = 0; // 分成多少组if(n%i==0) {ans1=n/i*1.0;}else {continue;}// 先统一测试ans+=ans1;// 恰好分成ans1组 每组i个人// 全部是阴性的概率double quanbuyingxing=1.0;for (int i1 = 0; i1 < i; i1++) {quanbuyingxing*=p;}// 有阳性的概率double youyang=1.0-quanbuyingxing;// 有多少组阳性的double yangzu=youyang*ans1*1.0;// 分别测ans+=yangzu*i;if(ans<num){num=ans;k=i;}}System.out.println(k);}public static void main(String[] args) throws Exception {int t = 1;
//        t = sc.nextInt();while (t-- > 0) {solve();}}}

F 星际旅行

我自己搓的版本 bfs

import java.util.*;
// 1:无需package
// 2: 类名必须Main, 不可修改public class Main {static ArrayList<ArrayList<Integer>>adj;public static void main(String[] args) {Scanner sc = new Scanner(System.in);// 邻接矩阵adj=new ArrayList<>();int n=sc.nextInt(); // n个星球int m=sc.nextInt(); // m道传送门int q=sc.nextInt(); // 盲盒long sum=0;for (int i = 0; i < n+5; i++) {adj.add(new ArrayList<>());}for (int i = 0; i < m; i++) {int u=sc.nextInt();int v=sc.nextInt();// 双向图adj.get(u).add(v);adj.get(v).add(u);}int arr[][]=new int[q][2];HashMap<Integer, Integer> hm = new HashMap<>();for (int i = 0; i < q; i++) {int u=sc.nextInt(); // 当前节点int cnt=sc.nextInt();  // 旅行卷轴 多少层arr[i][0]=u;arr[i][1]=cnt;if(hm.containsKey(u)==false){hm.put(u,cnt);}else {int value= hm.get(u);hm.put(u,Math.max(value,cnt));}}ArrayList<ArrayList<Integer>>yuchuli=new ArrayList<>();for (int i = 0; i < n+5; i++) {yuchuli.add(new ArrayList<>());}for (Integer i : hm.keySet()) {int u=i; // 当前节点int max=hm.get(u); // 最大旅行卷轴
//            System.out.println(u+" "+max);int ans=1; // 当前层有1个Queue<Integer>queue=new LinkedList<>();queue.add(u);int jishu=0; // 计数int sumsum=0;
//            System.out.println(sumsum);while (!queue.isEmpty()){Integer poll = queue.poll();
//                System.out.println(u+" "+poll);jishu++; // 计数for(int in:adj.get(poll)){if(in!=u){queue.add(in);}}if(jishu==ans){ans=queue.size();
//                    System.out.println("当前层有"+ans);sumsum+=jishu;
//                    System.out.println(u+" "+sumsum);yuchuli.get(u).add(sumsum);jishu=0;max--;if(max<0){break;}}}}for (int i = 0; i < q; i++) {Integer i1 = yuchuli.get(arr[i][0]).get(arr[i][1]);
//            System.out.println(i1);sum+=i1;}System.out.println(String.format("%.2f",(double)sum/(double) n/1.0));}
}

这是看了题解的版本 Floyd算法

import java.util.Scanner;public class Main {static int[][] d = new int[1010][1010];public static void main(String[] args) {Scanner sc = new Scanner(System.in);long n, m, Q;n = sc.nextInt();m = sc.nextInt();Q = sc.nextInt();for (int i = 1; i <= n; i++){for (int j = 1; j <= n; j++){if (i == j){d[i][j] = 0;}else {d[i][j] = (int) 1e9;}}}for (int i = 0; i < m; i++) {int a, b;a = sc.nextInt();b = sc.nextInt();d[a][b] = d[b][a] = 1;}// Floyd算法for (int k = 1; k <= n; k++)for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++)d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);double ans = 0;for (int i = 0; i < Q; i++) {int x, y;x = sc.nextInt();y = sc.nextInt();for (int j = 1; j <= n; j++){if (d[x][j] <= y) {ans = ans + 1;}}}System.out.printf("%.2f", ans / Q);}
}

G LITS 游戏

不会

import java.io.*;
import java.math.*;
import java.util.*;// LITS 游戏public class Main {static Scanner sc = new Scanner(System.in);static final long MOD = (long) (1e9+7);public static void solve() throws IOException {System.out.println("NO");}public static void main(String[] args) throws Exception {int t = 1;t = sc.nextInt();while (t-- > 0) {solve();}}}

H 拼十字

直接暴力的

import java.io.*;
import java.math.*;
import java.util.*;public class Main {static Scanner sc = new Scanner(System.in);static final long MOD = (long) (1e9+7);static class Pair{// 长long l;// 宽long w;// 带参构造Pair(long ll,long ww){this.l=ll;this.w=ww;}}public static void solve() throws IOException {int n=sc.nextInt();ArrayList<Pair>list0=new ArrayList<>();ArrayList<Pair>list1=new ArrayList<>();ArrayList<Pair>list2=new ArrayList<>();for(int i=0;i<n;i++) {long l=sc.nextLong(); // 长long w=sc.nextLong(); // 宽long c=sc.nextLong(); // 颜色if(c==0) {list0.add(new Pair(l,w));}else if(c==1){list1.add(new Pair(l,w));}else {list2.add(new Pair(l,w));}}long cnt=0;// 颜色0 和 颜色 1for(int i=0;i<list0.size();i++) {for(int j=0;j<list1.size();j++) {long chang1 = list0.get(i).l;long kuan1  = list0.get(i).w;long chang2 = list1.get(j).l;long kuan2  = list1.get(j).w;if( (chang1>chang2&&kuan1<kuan2) || (chang1<chang2&&kuan1>kuan2)) {cnt++;}}}// 颜色1 和 颜色2for(int i=0;i<list1.size();i++) {for(int j=0;j<list2.size();j++) {long chang1 = list1.get(i).l;long kuan1  = list1.get(i).w;long chang2 = list2.get(j).l;long kuan2  = list2.get(j).w;if( (chang1>chang2&&kuan1<kuan2) || (chang1<chang2&&kuan1>kuan2)) {cnt++;}}}// 颜色0 和 颜色2for(int i=0;i<list0.size();i++) {for(int j=0;j<list2.size();j++) {long chang1 = list0.get(i).l;long kuan1  = list0.get(i).w;long chang2 = list2.get(j).l;long kuan2  = list2.get(j).w;if( (chang1>chang2&&kuan1<kuan2) || (chang1<chang2&&kuan1>kuan2)) {cnt++;}}}System.out.print(cnt);}public static void main(String[] args) throws Exception {int t = 1;
//        t = sc.nextInt();while (t-- > 0) {solve();}}}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com