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

2022CCPC吉林省赛长春邀请赛 Java 做题记录

K. Bracket Sequence

卡特兰数 模版

// @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 IoScanner sc = new IoScanner();
//	static Scanner sc=new Scanner(System.in)static final int MOD = (int) (1e9 + 7);
//    static final int mod = (int) (998244353);static int n;static int arr[];static boolean visited[];static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();static int map[][];/*** @throws IOException*/private static void solve() throws IOException {long n=sc.nextLong();long k=sc.nextLong();// 每一种long sum1=1;//    	for(int i=0;i<n;i++) {
//    		sum1=Math.pow(n, k) ;
//    	}sum1*=powMod(k, n ,MOD) ;long sum2=catalanFormula(n);//    	dduoln(sum1);
//    	dduoln(sum2);dduoln((sum1*sum2)%MOD);}// 卡特兰数// 方法3:显式公式计算(带取模,使用逆元)public static long catalanFormula(long n) {if (n == 0) {return 1;}// 计算组合数 C(2n, n) / (n+1) mod MODlong result = 1;// 计算 C(2n, n) mod MODfor (int i = 1; i <= n; i++) {result = result * (n + i) % MOD;result = result * modInverse(i, MOD) % MOD;}// 除以 (n+1) 等同于乘以其逆元return result * modInverse(n + 1, MOD) % MOD;}// 计算 a 在模 m 下的逆元(要求 m 为质数)private static long modInverse(long a, long m) {return powMod(a, m - 2, m);}// 快速幂取模private static long powMod(long base, long exp, long mod) {long result = 1;base %= mod;while (exp > 0) {if (exp % 2 == 1) {result = result * base % mod;}base = base * base % mod;exp >>= 1;}return result;}/**1001 22 224 20*/public static void main(String[] args) throws Exception {int t = 1;t = sc.nextInt();while (t-- > 0) {solve();}}static <T> void dduo(T t) {System.out.print(t);}static <T> void dduoln() {System.out.println("");}static <T> void dduoln(T t) {System.out.println(t);}
}/*** IoScanner类** @author Dduo* @version 1.0* @description 通过IO流操作缓冲区减少了与底层输入输出设备的交互次数,旨在简化 Java 中的标准输入读取操作。*/
class IoScanner {BufferedReader bf;StringTokenizer st;BufferedWriter bw;public IoScanner() {bf = new BufferedReader(new InputStreamReader(System.in));st = new StringTokenizer("");bw = new BufferedWriter(new OutputStreamWriter(System.out));}public String nextLine() throws IOException {return bf.readLine();}public String next() throws IOException {while (!st.hasMoreTokens()) {st = new StringTokenizer(bf.readLine());}return st.nextToken();}public char nextChar() throws IOException {return next().charAt(0);}public int nextInt() throws IOException {return Integer.parseInt(next());}public long nextLong() throws IOException {return Long.parseLong(next());}public double nextDouble() throws IOException {return Double.parseDouble(next());}public float nextFloat() throws IOException {return Float.parseFloat(next());}public BigInteger nextBigInteger() throws IOException {return new BigInteger(next());}public BigDecimal nextDecimal() throws IOException {return new BigDecimal(next());}
}

L. Suzuran Loves String

// @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 IoScanner sc = new IoScanner();
//	static Scanner sc=new Scanner(System.in)
//    static final int mod = (int) (1e9 + 7);static final int mod = (int) (998244353);static int n;static int arr[];static boolean visited[];static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();static int map[][];/*** @throws IOException*/private static void solve() throws IOException {String str = sc.next();int n=str.length();HashSet<Character>hs=new HashSet<>();int p=-1;for(int i=0;i<str.length();i++) {hs.add(str.charAt(i));if(p==-1&&hs.size()>=2) {p=i;}}//    	dduoln(p);
//    	dduoln(n);if(hs.size()==1) {dduoln(str.length()-1);}else {dduoln((n-p)+(n));}}/***/public static void main(String[] args) throws Exception {int t = 1;t = sc.nextInt();while (t-- > 0) {solve();}}static <T> void dduo(T t) {System.out.print(t);}static <T> void dduoln() {System.out.println("");}static <T> void dduoln(T t) {System.out.println(t);}
}/*** IoScanner类** @author Dduo* @version 1.0* @description 通过IO流操作缓冲区减少了与底层输入输出设备的交互次数,旨在简化 Java 中的标准输入读取操作。*/
class IoScanner {BufferedReader bf;StringTokenizer st;BufferedWriter bw;public IoScanner() {bf = new BufferedReader(new InputStreamReader(System.in));st = new StringTokenizer("");bw = new BufferedWriter(new OutputStreamWriter(System.out));}public String nextLine() throws IOException {return bf.readLine();}public String next() throws IOException {while (!st.hasMoreTokens()) {st = new StringTokenizer(bf.readLine());}return st.nextToken();}public char nextChar() throws IOException {return next().charAt(0);}public int nextInt() throws IOException {return Integer.parseInt(next());}public long nextLong() throws IOException {return Long.parseLong(next());}public double nextDouble() throws IOException {return Double.parseDouble(next());}public float nextFloat() throws IOException {return Float.parseFloat(next());}public BigInteger nextBigInteger() throws IOException {return new BigInteger(next());}public BigDecimal nextDecimal() throws IOException {return new BigDecimal(next());}
}

B. Arithmetic Exercise

// @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 IoScanner sc = new IoScanner();
//	static Scanner sc=new Scanner(System.in)
//    static final int mod = (int) (1e9 + 7);static final int mod = (int) (998244353);static int n;static int arr[];static boolean visited[];static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();static int map[][];/*** @throws IOException*/private static void solve() throws IOException {long a=sc.nextLong();long b=sc.nextLong();long k=sc.nextLong();BigDecimal num1 = new BigDecimal(a);BigDecimal num2 = new BigDecimal(b);BigDecimal quotient = num1.divide(num2, (int) k, RoundingMode.HALF_UP);dduoln(quotient);}/***/public static void main(String[] args) throws Exception {int t = 1;
//        t = sc.nextInt();while (t-- > 0) {solve();}}static <T> void dduo(T t) {System.out.print(t);}static <T> void dduoln() {System.out.println("");}static <T> void dduoln(T t) {System.out.println(t);}
}/*** IoScanner类** @author Dduo* @version 1.0* @description 通过IO流操作缓冲区减少了与底层输入输出设备的交互次数,旨在简化 Java 中的标准输入读取操作。*/
class IoScanner {BufferedReader bf;StringTokenizer st;BufferedWriter bw;public IoScanner() {bf = new BufferedReader(new InputStreamReader(System.in));st = new StringTokenizer("");bw = new BufferedWriter(new OutputStreamWriter(System.out));}public String nextLine() throws IOException {return bf.readLine();}public String next() throws IOException {while (!st.hasMoreTokens()) {st = new StringTokenizer(bf.readLine());}return st.nextToken();}public char nextChar() throws IOException {return next().charAt(0);}public int nextInt() throws IOException {return Integer.parseInt(next());}public long nextLong() throws IOException {return Long.parseLong(next());}public double nextDouble() throws IOException {return Double.parseDouble(next());}public float nextFloat() throws IOException {return Float.parseFloat(next());}public BigInteger nextBigInteger() throws IOException {return new BigInteger(next());}public BigDecimal nextDecimal() throws IOException {return new BigDecimal(next());}
}

E. Great Detective TJC

// @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 IoScanner sc = new IoScanner();
//	static Scanner sc=new Scanner(System.in)
//    static final int mod = (int) (1e9 + 7);static final int mod = (int) (998244353);static int n;static int arr[];static boolean visited[];static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();static int map[][];/*** @throws IOException*/private static void solve() throws IOException {int n=sc.nextInt();long arr[]=new long[n];HashSet<Long> hs =new HashSet<>();for(int i=0;i<n;i++) {arr[i]=sc.nextLong();hs.add(arr[i]);}for(int i=0;i<n;i++) {if(arr[i]%2==0&&hs.contains(arr[i]+1)==true) {dduoln("Yes");return;}}dduoln("No");}/***/public static void main(String[] args) throws Exception {int t = 1;t = sc.nextInt();while (t-- > 0) {solve();}}static <T> void dduo(T t) {System.out.print(t);}static <T> void dduoln() {System.out.println("");}static <T> void dduoln(T t) {System.out.println(t);}
}/*** IoScanner类** @author Dduo* @version 1.0* @description 通过IO流操作缓冲区减少了与底层输入输出设备的交互次数,旨在简化 Java 中的标准输入读取操作。*/
class IoScanner {BufferedReader bf;StringTokenizer st;BufferedWriter bw;public IoScanner() {bf = new BufferedReader(new InputStreamReader(System.in));st = new StringTokenizer("");bw = new BufferedWriter(new OutputStreamWriter(System.out));}public String nextLine() throws IOException {return bf.readLine();}public String next() throws IOException {while (!st.hasMoreTokens()) {st = new StringTokenizer(bf.readLine());}return st.nextToken();}public char nextChar() throws IOException {return next().charAt(0);}public int nextInt() throws IOException {return Integer.parseInt(next());}public long nextLong() throws IOException {return Long.parseLong(next());}public double nextDouble() throws IOException {return Double.parseDouble(next());}public float nextFloat() throws IOException {return Float.parseFloat(next());}public BigInteger nextBigInteger() throws IOException {return new BigInteger(next());}public BigDecimal nextDecimal() throws IOException {return new BigDecimal(next());}
}

A. Random Number Checker

// @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 IoScanner sc = new IoScanner();
//	static Scanner sc=new Scanner(System.in)
//    static final int mod = (int) (1e9 + 7);static final int mod = (int) (998244353);static int n;static int arr[];static boolean visited[];static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();static int map[][];/*** @throws IOException*/private static void solve() throws IOException {int n=sc.nextInt();int ji=0;int ou=0;for(int i=0;i<n;i++) {int ans=sc.nextInt();if(ans%2==0) {ou++;}else {ji++;}}if(Math.abs(ji-ou)<=1) {dduoln("Good");}else {dduoln("Not Good");}}/***/public static void main(String[] args) throws Exception {int t = 1;
//        t = sc.nextInt();while (t-- > 0) {solve();}}static <T> void dduo(T t) {System.out.print(t);}static <T> void dduoln() {System.out.println("");}static <T> void dduoln(T t) {System.out.println(t);}
}/*** IoScanner类** @author Dduo* @version 1.0* @description 通过IO流操作缓冲区减少了与底层输入输出设备的交互次数,旨在简化 Java 中的标准输入读取操作。*/
class IoScanner {BufferedReader bf;StringTokenizer st;BufferedWriter bw;public IoScanner() {bf = new BufferedReader(new InputStreamReader(System.in));st = new StringTokenizer("");bw = new BufferedWriter(new OutputStreamWriter(System.out));}public String nextLine() throws IOException {return bf.readLine();}public String next() throws IOException {while (!st.hasMoreTokens()) {st = new StringTokenizer(bf.readLine());}return st.nextToken();}public char nextChar() throws IOException {return next().charAt(0);}public int nextInt() throws IOException {return Integer.parseInt(next());}public long nextLong() throws IOException {return Long.parseLong(next());}public double nextDouble() throws IOException {return Double.parseDouble(next());}public float nextFloat() throws IOException {return Float.parseFloat(next());}public BigInteger nextBigInteger() throws IOException {return new BigInteger(next());}public BigDecimal nextDecimal() throws IOException {return new BigDecimal(next());}
}

M. Sequence

// @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 IoScanner sc = new IoScanner();
//	static Scanner sc=new Scanner(System.in)
//    static final int mod = (int) (1e9 + 7);static final int mod = (int) (998244353);static int n;static int arr[];static boolean visited[];static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();static int map[][];/*** @throws IOException*/private static void solve() throws IOException {int n=sc.nextInt();long arr[]=new long[n];for(int i=0;i<n;i++) {arr[i]=sc.nextLong();}long max=Long.MIN_VALUE;long min=Long.MAX_VALUE;for(int i=0;i<n;i++) {max=Math.max(max, arr[i]);min=Math.min(min, arr[i]);}dduoln( (max-min)*n );}/***/public static void main(String[] args) throws Exception {int t = 1;
//        t = sc.nextInt();while (t-- > 0) {solve();}}static <T> void dduo(T t) {System.out.print(t);}static <T> void dduoln() {System.out.println("");}static <T> void dduoln(T t) {System.out.println(t);}
}/*** IoScanner类** @author Dduo* @version 1.0* @description 通过IO流操作缓冲区减少了与底层输入输出设备的交互次数,旨在简化 Java 中的标准输入读取操作。*/
class IoScanner {BufferedReader bf;StringTokenizer st;BufferedWriter bw;public IoScanner() {bf = new BufferedReader(new InputStreamReader(System.in));st = new StringTokenizer("");bw = new BufferedWriter(new OutputStreamWriter(System.out));}public String nextLine() throws IOException {return bf.readLine();}public String next() throws IOException {while (!st.hasMoreTokens()) {st = new StringTokenizer(bf.readLine());}return st.nextToken();}public char nextChar() throws IOException {return next().charAt(0);}public int nextInt() throws IOException {return Integer.parseInt(next());}public long nextLong() throws IOException {return Long.parseLong(next());}public double nextDouble() throws IOException {return Double.parseDouble(next());}public float nextFloat() throws IOException {return Float.parseFloat(next());}public BigInteger nextBigInteger() throws IOException {return new BigInteger(next());}public BigDecimal nextDecimal() throws IOException {return new BigDecimal(next());}
}
http://www.xdnf.cn/news/7840.html

相关文章:

  • 软考软件评测师—— 操作系统综合知识
  • RedissonClient主要功能概述
  • 黑马点评相关知识总结
  • 大模型会话窗口为什么对最新和最久记忆表现较好
  • 13 分钟讲解所有知名 Python 库/模块
  • 命名常量集合接口INamedConstantCollection<T>实现
  • 顶级流媒体服务商 Spotify 2025.04 故障复盘报告,吃他人的堑长自己的智
  • 4.8 加密模块
  • 无人机报警器360°检测技术分析!
  • 先验知识融合机器学习的几种方式
  • VentureBeat AI 最新资讯 (2025-05-19)
  • NVM安装使用及问题解决
  • Semaphore解决高并发场景下的有限资源的并发访问问题
  • 整型数相加的溢出
  • Python的蚁群优化算法实现与多维函数优化实战
  • 【Java高阶面经:微服务篇】1.微服务架构核心:服务注册与发现之AP vs CP选型全攻略
  • C语言指针深入详解(五):回调函数、qsort函数
  • 卡片布局自适应
  • c语言刷题之实际问题
  • 一文读懂|大模型智能体互操作协议:MCP/ACP/A2A/ANP
  • Redis学习专题(三)主从复制
  • 单端IO和差分IO标准
  • 《Metasploit框架核心模块解析与安全防护实践》​
  • 树 Part 6
  • 2025年PMP 学习二十二 15章 项目绩效域
  • BUUCTF——Kookie
  • FEKO许可证与其他电磁仿真软件的比较
  • 《算法笔记》11.1小节——动态规划专题->动态规划的递归写法和递推写法 问题 A: Fibonacci
  • 嵌入式自学第二十四天(5.20)
  • Stack Queue