当前位置: 首页 > ops >正文

蓝桥杯国赛训练 day3

目录

01串的个数

互质的数

阶乘求值

密文搜索

蓝桥字符

穿越雷区

Excel地址


01串的个数

import java.util.*;public class Main {static Scanner sc = new Scanner(System.in);public static void main(String[] args) {solve();}static int cnt=0;public static void solve() {for(int i1=0;i1<=1;i1++) {for(int i2=0;i2<=1;i2++) {for(int i3=0;i3<=1;i3++) {for(int i4=0;i4<=1;i4++) {for(int i5=0;i5<=1;i5++) {for(int i6=0;i6<=1;i6++) {for(int i7=0;i7<=1;i7++) {for(int i8=0;i8<=1;i8++) {for(int i9=0;i9<=1;i9++) {for(int i10=0;i10<=1;i10++) {for(int i11=0;i11<=1;i11++) {for(int i12=0;i12<=1;i12++) {for(int i13=0;i13<=1;i13++) {for(int i14=0;i14<=1;i14++) {for(int i15=0;i15<=1;i15++) {for(int i16=0;i16<=1;i16++) {for(int i17=0;i17<=1;i17++) {for(int i18=0;i18<=1;i18++) {for(int i19=0;i19<=1;i19++) {for(int i20=0;i20<=1;i20++) {for(int i21=0;i21<=1;i21++) {for(int i22=0;i22<=1;i22++) {for(int i23=0;i23<=1;i23++) {for(int i24=0;i24<=1;i24++) {StringBuilder sb=new StringBuilder("");sb.append(i1+"").append(i2+"").append(i3+"").append(i4+"").append(i5+"").append(i6+"").append(i7+"").append(i8+"").append(i9+"").append(i10+"").append(i11+"").append(i12+"").append(i13+"").append(i14+"").append(i15+"").append(i16+"").append(i17+"").append(i18+"").append(i19+"").append(i20+"").append(i21+"").append(i22+"").append(i23+"").append(i24+"");judge(sb.toString());}	}	}	}	}	}	}	}	}}}	}	}	}	}	}	}	}	}	}	}	}	}}System.out.println("2963628");}private static void judge(String str) {// TODO Auto-generated method stub
//		System.out.println(str);
//		满足任意 5 个连续的位置中不超过 3 个位置的值为 1。for(int i=0;i<=24-5;i++) {int ans=0;if(str.charAt(i)=='1') ans++;if(str.charAt(i+1)=='1') ans++;if(str.charAt(i+2)=='1') ans++;if(str.charAt(i+3)=='1') ans++;if(str.charAt(i+4)=='1') ans++;if(ans>3)return;}System.out.println(str);cnt++;return;}}

互质的数


 

import java.util.*;public class Main {static Scanner sc = new Scanner(System.in);public static void main(String[] args) {solve();}static int cnt=0;public static void solve() {for(int num2=1;;num2++) {long num1=2024;if(judge(num1,num2)==true) {cnt++;System.out.println(cnt+" "+num2);if(cnt==2024){return;}}}//		System.out.println("4655");}// 判断两个数是不是互质private static boolean judge(long num1,long num2) {for(int i=2;i<=Math.min(num1,num2);i++) {if(num1%i==0&&num2%i==0) {return false;}}return true;}}

阶乘求值

import java.math.*;
import java.util.*;public class Main {static Scanner sc = new Scanner(System.in);//    static long mod=1000000007;static BigInteger mod=new BigInteger("1000000007");public static void main(String[] args) {solve();}public static void solve() {//		BigInteger b=new BigInteger("1");long target=sc.nextLong();BigInteger b1=new BigInteger(target+"");//    	while(b.compareTo(b1)<0) {
//    		 
//    		BigInteger ans=new BigInteger("1");
//    		BigInteger cnt=new BigInteger("1");
//    		while(ans.compareTo(b)<0) {
//    			cnt=cnt.multiply(ans);
//    			ans=ans.add(new BigInteger("1"));
//    		}System.out.println(cnt+" "+cnt.mod(mod));
//    		b=b.add(new BigInteger("1"));
//    		
//    	}BigInteger ans=new BigInteger("1");BigInteger cnt=new BigInteger("1");while(ans.compareTo(b1)<=0) {cnt=cnt.multiply(ans);
//			System.out.println(ans);ans=ans.add(new BigInteger("1"));cnt=cnt.mod(mod);}
//		System.out.println(cnt+" "+cnt.mod(mod));
//		b=b.add(new BigInteger("1"));System.out.print(cnt.mod(mod));}/**
1
2
6
24
120
720
5040
40320
362880
3628800
39916800*/}

密文搜索

import java.math.*;
import java.util.*;public class Main {static Scanner sc = new Scanner(System.in);//    static long mod=1000000007;static BigInteger mod=new BigInteger("1000000007");public static void main(String[] args) {solve();}public static void solve() {String str=sc.next();// 输入字符串int n=sc.nextInt();String arr[]=new String[n];for(int i=0;i<n;i++) {arr[i]=sc.next();}if(str.length()<8) {System.out.println("0");return;}// 先存前8个字符int strArr[]=new int[26];for(int i=0;i<8;i++) {strArr[ str.charAt(i)-'a' ]++;}int copy[]=new int[26];for(int i=0;i<26;i++) {copy[i]=strArr[i];}long cnt=0;for(int i=0;i<arr.length;i++) {String ansStr = arr[i];int ansStrArr[]=new int[26];// 把当前字符存入for(int i1=0;i1<ansStr.length();i1++) {ansStrArr[ ansStr.charAt(i1)-'a' ]++;}for(int i1=0;i1<26;i1++) {strArr[i1]=copy[i1];}// 单独对1特判boolean judge1=true;for(int i1=0;i1<26;i1++) {if(strArr[i1]!=ansStrArr[i1]) {judge1=false;break;}}if(judge1==true) {cnt++;}// 滑动窗口int pi=0,pj=8;while(pj<str.length()) {strArr[ str.charAt(pi)-'a' ]--;strArr[ str.charAt(pj)-'a' ]++;boolean judge=true;for(int i1=0;i1<26;i1++) {if(strArr[i1]!=ansStrArr[i1]) {judge=false;break;}}if(judge==true)cnt++;pj++;pi++;}}System.out.println(cnt);}}

蓝桥字符

import java.math.*;
import java.util.*;public class Main {static Scanner sc = new Scanner(System.in);public static void main(String[] args) {int t = 1;
//    	t=sc.nextInt();for(int i=0;i<t;i++) {solve();}}public static void solve() {String str=sc.next();int n=str.length();long pre_l[]=new long[n+1];long pre_n[]=new long[n+1];// 存前缀for(int i=1;i<=n;i++) {pre_l[i]=pre_l[i-1];if(str.charAt(i-1)=='l') {pre_l[i]++;}}// 存后缀for(int i=n-1;i>=0;i--) {pre_n[i]=pre_n[i+1];if(str.charAt(i)=='n') {pre_n[i]++;}}//    	for(int i=0;i<n+1;i++) {
//    		System.out.print(pre_l[i]+" ");
//    	}
//    	System.out.println("");
//    	for(int i=0;i<n+1;i++) {
//    		System.out.print(pre_n[i]+" ");
//    	}
//    	System.out.println("");long cnt=0;for(int i=0;i<str.length();i++) {if(str.charAt(i)=='a') {cnt+=pre_l[i]*pre_n[i];}}System.out.println(cnt);}}

穿越雷区

import java.math.*;
import java.util.*;public class Main {static Scanner sc = new Scanner(System.in);public static void main(String[] args) {int t = 1;
//    	t=sc.nextInt();for(int i=0;i<t;i++) {solve();}}static int n;// 地图static char map[][];// 记录最短路 到达各个坐标的最小步数static long min[][];// A的坐标static int a_x=-1,a_y=-1;// B的坐标static int b_x=-1,b_y=-1;public static void solve() {n=sc.nextInt();map=new char[n][n];min=new long[n][n];for(int i1=0;i1<n;i1++) {for(int i2=0;i2<n;i2++) {map[i1][i2]=sc.next().charAt(0);if(map[i1][i2]=='A') {a_x=i1;a_y=i2;}if(map[i1][i2]=='B') {b_x=i1;b_y=i2;}}}// 初始化最短路数组for(int i1=0;i1<n;i1++) {for(int i2=0;i2<n;i2++) {min[i1][i2]=Long.MAX_VALUE;}}min[a_x][a_y]=0;dfs(a_x,a_y,map[a_x][a_y],-1);System.out.println(min[b_x][b_y]);//    	for(int i=0;i<n;i++) {
//    		for(int j=0;j<n;j++) {
//    			System.out.print(min[i][j]+" ");
//    		}
//    		System.out.println("");
//    	}}/*** 递归* @param x 横坐标 * @param y 纵坐标* @param c 当前镭射符号*/private static void dfs(int x, int y, char c,int time) {//		System.out.println(map[x][y]+" "+x+" "+y);time++;// 递归出口if(x==b_x&&y==b_y) {
//			System.out.println(time);min[b_x][b_y]=Math.min(time, min[b_x][b_y]);return;}int newx=0,newy=0;if(x==a_x&&y==a_y) {// 上newx=x; newy=y-1;if(newx>=0&&newx<n&&newy>=0&&newy<n) {dfs(newx,newy,map[newx][newy],time);}// 下newx=x; newy=y+1;if(newx>=0&&newx<n&&newy>=0&&newy<n) {dfs(newx,newy,map[newx][newy],time);}// 左newx=x-1; newy=y;if(newx>=0&&newx<n&&newy>=0&&newy<n) {dfs(newx,newy,map[newx][newy],time);}// 右newx=x+1; newy=y;if(newx>=0&&newx<n&&newy>=0&&newy<n) {dfs(newx,newy,map[newx][newy],time);}}if(time>=min[x][y])return;else {min[x][y]=time;}// 递归函数if(c=='-') { // 找 +// 上newx=x; newy=y-1;if(newx>=0&&newx<n&&newy>=0&&newy<n&& (map[newx][newy]=='+'||map[newx][newy]=='B') ) {dfs(newx,newy,'+',time);}// 下newx=x; newy=y+1;if(newx>=0&&newx<n&&newy>=0&&newy<n&& (map[newx][newy]=='+'||map[newx][newy]=='B') ) {dfs(newx,newy,'+',time);}// 左newx=x-1; newy=y;if(newx>=0&&newx<n&&newy>=0&&newy<n&& (map[newx][newy]=='+'||map[newx][newy]=='B') ) {dfs(newx,newy,'+',time);}// 右newx=x+1; newy=y;if(newx>=0&&newx<n&&newy>=0&&newy<n&& (map[newx][newy]=='+'||map[newx][newy]=='B') ) {dfs(newx,newy,'+',time);}}else if(c=='+'){// 上newx=x; newy=y-1;if(newx>=0&&newx<n&&newy>=0&&newy<n&& (map[newx][newy]=='-'||map[newx][newy]=='B') ) {dfs(newx,newy,'-',time);}// 下newx=x; newy=y+1;if(newx>=0&&newx<n&&newy>=0&&newy<n&& (map[newx][newy]=='-'||map[newx][newy]=='B') ) {dfs(newx,newy,'-',time);}// 左newx=x-1; newy=y;if(newx>=0&&newx<n&&newy>=0&&newy<n&& (map[newx][newy]=='-'||map[newx][newy]=='B') ) {dfs(newx,newy,'-',time);}// 右newx=x+1; newy=y;if(newx>=0&&newx<n&&newy>=0&&newy<n&& (map[newx][newy]=='-'||map[newx][newy]=='B') ) {dfs(newx,newy,'-',time);}}}}/**
5
A B - + -
- + - - +
- + + + -
+ - + - +
- + - + - */

Excel地址

import java.math.*;
import java.util.*;public class Main {static Scanner sc = new Scanner(System.in);public static void main(String[] args) {int t = 1;
//    	t=sc.nextInt();for(int i=0;i<t;i++) {solve();}}   public static void solve() {int n = sc.nextInt();StringBuilder result = new StringBuilder();while (n > 0) {n--;result.append((char) (n % 26 + 'A'));n /= 26;}System.out.print(result.reverse().toString());}}
http://www.xdnf.cn/news/13178.html

相关文章:

  • C++ 8.1 内联函数
  • 【Nginx系列】Nginx 负载均衡策略之 least_conn
  • shell脚本--查看应用的cpu 和 内存使用率 并把最新告警内容显示出来
  • Huggingface-CLI的使用
  • AIStarter 4.0 苹果版体验评测|轻松部署 ComfyUI 与 DeepSeek 的 AI 工具箱
  • 二刷苍穹外卖 day01
  • 为MySQL社区版实现审计功能:从插件配置到日志监控全解析
  • python 本地运行Qwen3-Embedding-0.6B 模型提供API接口
  • 【QT】通讯类HttpAPI:获取MAC、主机IP、端口IP有效性判断
  • CTFSHOW pwn143 WP
  • linux 更新ollama服务
  • 亚马逊云科技 Amazon Pinpoint 解决方案:构建智能全渠道互动平台,重塑用户增长体验
  • 数据库管理与高可用-PostgreSQL初体验
  • [特殊字符] 智能合约中的数据是如何在区块链中保持一致的?
  • 安全生产管理是什么?安全生产管理系统都有哪些核心功能?
  • Android 应用开发概述与环境搭建指南
  • DBSyncer:一款开源的数据同步工具
  • Windows上SSH连接Ubuntu失败
  • 记录下three.js学习过程中不理解问题③
  • pnpm安装和使用
  • Hyperlane 框架详解与使用指南
  • 如何使用java把文件转成十六进制字符串
  • DevSecOps实践:CI/CD流水线集成SAST工具详解
  • 8.1.排序的基本概念
  • 麒麟系统集成开发环境Kylin-IDE初体验,菜鸟小白入门教程
  • 基于vue+js的微信小程序高血压健康管理系统的设计与实现(源码+论文+调试+安装+售后)
  • 在微信小程序中使用骨架屏
  • 微信小程序之bind和catch
  • USB over Network技术重塑中国电气装备集团U盾智能化管控
  • Vue大文件上传:让你的文件秒传、断点续传、分片上传---需要后端支持--案例后端使用node