当前位置: 首页 > 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));}}
}
http://www.lryc.cn/news/310213.html

相关文章:

  • [数据集][目标检测]鸟类检测数据集VOC+YOLO格式11758张200类别
  • YOLOv9:使用可编程梯度信息学习您想学习的内容
  • uniapp:使用DCloud的uni-push推送消息通知(在线模式)java实现
  • 【简说八股】面试官:你知道什么是AOP么?
  • ASUS华硕天选5笔记本电脑FX607JV原装出厂Win11系统下载
  • Unity(第二十一部)动画的基础了解(感觉不了解其实也行)
  • 写时复制简介
  • 运行Python文件时出现‘utf-8’code can‘t decode byte 如何解决?(如图)
  • 行为树入门:BehaviorTree.CPP Groot2练习(叶子节点)(2)
  • leetcode-字符串中的单词数
  • 一些C语言题目
  • JVM相关问题
  • 32单片机基础:旋转编码器计次
  • 【C++】vector的使用和模拟实现(超级详解!!!!)
  • GO学习记录
  • 迭代器模式(Iterator Pattern)
  • KL divergence(KL 散度)详解
  • AzerothCore@FreeBSD安装记录
  • vue .env配置环境变量
  • ThreadLocal介绍
  • 【Linux系统化学习】线程概念
  • Redis集群模式
  • 执行go get xxx报错
  • MATLAB基础语法与实践
  • 智能边缘小站 CloudPond(低延迟、高带宽和更好的数据隐私保护)
  • 回归预测 | Matlab实现RIME-BP霜冰算法优化BP神经网络多变量回归预测
  • LeetCode15:三数之和
  • 【详识JAVA语言】面向对象程序三大特性之三:多态
  • nginx(三)实现反向代理客户端 IP透传
  • 深入Java日志框架及其最佳实践