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

蓝桥杯(3.2)

1209. 带分数

import java.io.*;public class Main
{static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));static final int N = 10;static int n, cnt;static int[] a = new int[N];static boolean[] st = new boolean[N];public static int calc(int l, int r){int res = 0;for (int i = l; i <= r; i ++ )res = res * 10 + a[i];return res;}public static void dfs(int u){if (u > 9){for (int i = 1; i <= 7; i ++ )for (int j = i + 1; j <= 8; j ++ ){int a = calc(1, i), b = calc(i + 1, j), c = calc(j + 1, 9);if (a * c + b == c * n) cnt ++ ;}return;}for (int i = 1; i <= 9; i ++ )if (!st[i]){a[u] = i;st[i] = true;dfs(u + 1);a[u] = 0;st[i] = false;}}public static void main(String[] args) throws IOException{n = Integer.parseInt(br.readLine());dfs(1);pw.print(cnt);pw.flush();pw.close();}
}

717. 简单斐波那契

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();int f1 = 0;int f2 = 1;for(int i=1;i<=n;i++) {int f3 = f1 + f2;System.out.print(f1+" ");f1 = f2;f2 = f3;}}
}

P1255 数楼梯

import java.math.BigInteger;
import java.util.Scanner;public class Main {static BigInteger f1 = new BigInteger("1");static BigInteger f2 = new BigInteger("2");static BigInteger f3 = new BigInteger("0");public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();//1 2 3 5 ...if (n == 1) {System.out.println(f1);} else if (n == 2) {System.out.println(f2);} else {for (int i = 3; i <= n; i++) {f3 = f1.add(f2);f1 = f2;f2 = f3;}System.out.println(f3);}}
}

P1036 [NOIP2002 普及组] 选数

import java.util.Scanner;public class Main {static int n;static int m;static final int N = 21;static int[] a = new int[N];static int[] b = new int[N];static int ans;public static boolean isPrime(int n) {for(int i=2;i<n;i++) {if(n%i == 0)return false;}return true;}public static void dfs(int u,int start) {if(u > m) {int sum = 0;for(int i=1;i<=m;i++) {sum+=b[i];}if(isPrime(sum)) {ans++;}return ;}for(int i=start;i<=n;i++) {b[u] = a[i];dfs(u+1,i+1);b[u] = 0;}}public static void main(String[] args) {Scanner sc = new Scanner(System.in);n = sc.nextInt();m = sc.nextInt();for(int i=1;i<=n;i++) {a[i] = sc.nextInt();}dfs(1,1);System.out.println(ans);}
}

P1028 [NOIP2001 普及组] 数的计算

import java.util.Scanner;
public class Main{//6public static int dfs(int x) {if (x == 1) {return 1;}int tot = 1;//longfor (int i = 1; i <= x / 2; i++) {tot += dfs(i);}return tot;}public static void main(String[] args){    	Scanner sc = new Scanner(System.in);int n = sc.nextInt();System.out.println(dfs(n));}
}

在这里插入图片描述
P1464 Function

import java.util.Scanner;public class Main {static int N = 21;static long[][][] s = new long[N][N][N];public static long w(long a,long b,long c) {if(a<=0||b<=0||c<=0)return 1;if(a>20||b>20||c>20)return s[20][20][20];if(a<b&&b<c)return s[(int)a][(int)b][(int)c-1]+s[(int)a][(int)b-1][(int)c-1]-s[(int)a][(int)b-1][(int)c];return s[(int)a-1][(int)b][(int)c]+s[(int)a-1][(int)b-1][(int)c]+s[(int)a-1][(int)b][(int)c-1]-s[(int)a-1][(int)b-1][(int)c-1];}public static void main(String[] args) {Scanner sc = new Scanner(System.in);long a,b,c;for(int i=0;i<=20;i++)for(int j=0;j<=20;j++)for(int k=0;k<=20;k++)s[i][j][k] = w(i,j,k);// 输入a、b、c,计算w(a, b, c)并输出结果while (true) {a = sc.nextLong();b = sc.nextLong();c = sc.nextLong();if (a == -1 && b == -1 && c == -1)return ;elseSystem.out.println("w(" + a + ", " + b + ", " + c + ") = " + w(a, b, c));}}
}

相关文章:

  • Linux学习-etcdctl安装
  • Qt | 停靠窗体显示日历和文本编辑器
  • libvirt命名空间xmlns:qemu的使用
  • Unity UGUI之Slider基本了解
  • SQL注入漏洞解析--less-7
  • 将博客搬家至微信公众号
  • springboot项目如何调用webservice-soap接口
  • IIC协议总结
  • 【MySQL】深入解析 Buffer Pool 缓冲池
  • 用 TVMC 编译和优化模型(2)
  • vue3输入单号和张数,自动生成连号的单号
  • 初阶数据结构之---栈和队列(C语言)
  • 【04】C语言括号匹配问题
  • WebServer -- 注册登录
  • Spring Cloud Gateway-系统保护Sentinel集成
  • 【许晓笛】 EOS 智能合约案例解析(3)
  • Android交互
  • Angularjs之国际化
  • ESLint简单操作
  • Fundebug计费标准解释:事件数是如何定义的?
  • Js基础知识(一) - 变量
  • python3 使用 asyncio 代替线程
  • SQLServer之创建数据库快照
  • VirtualBox 安装过程中出现 Running VMs found 错误的解决过程
  • vue自定义指令实现v-tap插件
  • 程序员该如何有效的找工作?
  • 初识MongoDB分片
  • 翻译:Hystrix - How To Use
  • 基于Volley网络库实现加载多种网络图片(包括GIF动态图片、圆形图片、普通图片)...
  • 快速体验 Sentinel 集群限流功能,只需简单几步
  • 日剧·日综资源集合(建议收藏)
  • 如何使用 JavaScript 解析 URL
  • 赢得Docker挑战最佳实践
  • 用简单代码看卷积组块发展
  • linux 淘宝开源监控工具tsar
  • ​软考-高级-系统架构设计师教程(清华第2版)【第15章 面向服务架构设计理论与实践(P527~554)-思维导图】​
  • # 深度解析 Socket 与 WebSocket:原理、区别与应用
  • #define用法
  • #stm32整理(一)flash读写
  • (14)学习笔记:动手深度学习(Pytorch神经网络基础)
  • (C#)获取字符编码的类
  • (Redis使用系列) Springboot 整合Redisson 实现分布式锁 七
  • (考研湖科大教书匠计算机网络)第一章概述-第五节1:计算机网络体系结构之分层思想和举例
  • (十一)图像的罗伯特梯度锐化
  • (五)Python 垃圾回收机制
  • (转)iOS字体
  • .helper勒索病毒的最新威胁:如何恢复您的数据?
  • .NET DevOps 接入指南 | 1. GitLab 安装
  • .Net Remoting(分离服务程序实现) - Part.3
  • .Net Web项目创建比较不错的参考文章
  • .NET 使用 JustAssembly 比较两个不同版本程序集的 API 变化
  • @test注解_Spring 自定义注解你了解过吗?
  • [ solr入门 ] - 利用solrJ进行检索
  • []我的函数库
  • [AIGC] 使用Curl进行网络请求的常见用法