牛客周赛85 题解 Java ABCDEFG

A小紫的均势博弈

判断输入的 n 是奇数还是偶数

import java.io.*;
import java.math.*;
import java.util.*;public class Main {static IoScanner sc = new IoScanner();static final int mod=(int) (1e9+7);static void solve() throws IOException {int n=sc.nextInt();if(n%2==0) {dduoln("yukari");}else {dduoln("kou");}} 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);}}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小紫的劣势博弈

排序 然后一人拿一个

import java.io.*;
import java.math.*;
import java.util.*;public class Main {static IoScanner sc = new IoScanner();static final int mod=(int) (1e9+7);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();}Arrays.sort(arr);long ans=0;for(int i=0;i<n;i++) {if(i%2==0) {ans+=arr[i];}else {ans+=arr[i]*(-1);}}dduoln(ans);} 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);}}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());}
}

C小紫的01串操作

通过观察我们发现

操作 1001 等效于操作 101

操作 100010011000 等效于操作 101010

然后发现经过小红和小紫操作

10 可以 10 -> 11

101 可以 101 -> 111

1010 可以 1010 -> 1110 -> 1111

10101 可以 10101 -> 10001 -> 11111

101010 不可以
...

所以只要判断出现多少次 01 就可以

import java.io.*;
import java.math.*;
import java.util.*;public class Main {static IoScanner sc = new IoScanner();static final int mod=(int) (1e9+7);static void solve() throws IOException {String str=sc.next();int a=1;for(int i=1;i<str.length();i++) {if(str.charAt(i)!=str.charAt(i-1)) {a++;}}if(a<=5) {dduoln("Yes");}else {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);}}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());}
}

D小紫的优势博弈

准备先暴力一发的 结果直接过了

10010

小红操作会有 5 种情况 这等于 n

0010

010

10

1

我的想法是一个一个从头开始遍历这些字符串

统计 1 0 出现的次数

如果都出现偶数次 那么小紫获胜

import java.io.*;
import java.math.*;
import java.util.*;// xixi♡西
public class Main {static IoScanner sc = new IoScanner();static final int mod=(int) (1e9+7);static void solve() throws IOException {int n=sc.nextInt();String str=sc.next();int cnt=0;for(int i=1;i<n;i++) {int cnt0=0;int cnt1=0;for(int j=i;j<n;j++) {if(str.charAt(j)=='1')cnt1++;if(str.charAt(j)=='0')cnt0++;if(cnt0!=0||cnt1!=0) {if(cnt0%2==0&&cnt1%2==0) {cnt++;break;}}}}dduoln((double)cnt/(double)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);}}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小紫的线段染色

首先要知道的是 有符合的情况

一部分染紫色 一部分染红色 等效于 一部分染红色 一部分染紫色

我们可以将结构体排序

int arr []{起始 l,结束 r,当前次序 i}

按照 l 从小到大 r 从小到大次之

第一段为红色 那么红色的末尾为 arr[0][2]

然后 从第二段 进行遍历

如果第二段的起始 l 小于红色末尾

那必须染成紫色

但如果起始 l 小于紫色末尾

那就无法染成了(输出-1 return)

如果 l 大于紫色末尾 则可以染成紫色 更新紫色末尾为第二段结束的 r

同时记录当前 arr[][3]

继续遍历

如果第三段的起始 l 大于红色末尾 更新红色末尾为第二段结束的 r

...

这边有个坑 就是

得 必须 选出一个染成紫色...

不能全是红色

import java.util.*;
import java.io.*;
import java.math.*; public class Main {static IoScanner sc = new IoScanner();static final int mod=(int) (1e9+7);public static void main(String[] args) throws IOException {int n=sc.nextInt();List<Long []>list=new ArrayList<>();for(long i=0;i<n;i++) {long l=sc.nextLong();long r=sc.nextLong();list.add(new Long[] {l,r, i+1});}Collections.sort(list,(o1,o2)->{if(o1[0]==o2[0]) {return Long.compare(o1[1], o2[1]);}else {return Long.compare(o1[0], o2[0]);}});ArrayList<Long> anslist=new ArrayList<>();long hongend=list.get(0)[1];long ziend=-1;for(int i=1;i<n;i++) {long start=list.get(i)[0];long end=list.get(i)[1];if(start<=hongend) { // 要变成紫色if(ziend==-1) {// 直接赋值ziend=end;}else {if(start<=ziend) {dduoln("-1");return;}else {ziend=end;}}// 变成紫色anslist.add((list.get(i)[2]));}else {// 继续红色hongend=end;}}if(anslist.size()==0) {anslist.add((long) 1);}dduoln(anslist.size());Collections.sort(anslist);for(long i:anslist) {dduo(i+" ");}}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);}
}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());}
}

F小紫的树上染色

import java.util.*; 
import java.io.*;
import java.math.*; public class Main {static IoScanner sc = new IoScanner();static final int mod=(int) (1e9+7);static int n;static int k;// 邻边矩阵static List<List<Integer>> list;public static void main(String[] args) throws IOException {n = sc.nextInt(); k = sc.nextInt(); if(k==n) {dduoln("0");return;}list = new ArrayList<>();for (int i = 0; i <= n; i++) {list.add(new  ArrayList<>());}for(int i=0;i<n-1;i++){ // 无向图int u=sc.nextInt();int v=sc.nextInt();list.get(u).add(v);list.get(v).add(u);}int low = 1;int high = n;int ans=n;while (low <= high) {int mid = (low + high) >> 1;if (check(mid, k)) {ans = mid;high = mid - 1;} else {low = mid + 1;}}dduoln(ans); }static boolean check(int mid, int k) {int[] res = new int[n+5];int cnt = 0;Deque<Object[]> stack = new ArrayDeque<>();stack.push(new  Object[]{1, -1, false});while (!stack.isEmpty())  {Object[] cur = stack.pop(); int u = (Integer) cur[0];int p = (Integer) cur[1];boolean judge = (Boolean) cur[2];if (judge==false) { // 未染色stack.push(new  Object[]{u, p, true});List<Integer> children = new ArrayList<>();for (int v : list.get(u))  { // v邻点  u当前顶点  p父顶点if (v != p) {children.add(v); }}
//                for(Integer i:children) {
//                	dduo(i);
//                }
//                dduoln();Collections.reverse(children); for (int v : children) {stack.push(new  Object[]{v, u, false});}} else { // 染色int sum = 0;for (int v : list.get(u))  {  // v邻点  u当前顶点  p父顶点if (v != p) {sum += res[v];}}if (sum + 1 > mid) {cnt++;res[u] = 0;} else {res[u] = sum + 1;}}}if(cnt <= k)return true;else return false;}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);}
}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.mzph.cn/web/72721.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python——UI自动化(1) selenium之介绍和环境配置

一、selenium介绍 selenium是一个第三方库&#xff0c;python有很多库&#xff1b; 1、什么是ui自动化? 通过模拟手工操作用户ui页面的方式&#xff0c;用代码去实现自动化操作和验证的行为。 2、ui自动化的优点&#xff1f; &#xff08;1&#xff09;解决重复性的功能测…

Can通信流程

下面给出一个更详细的 CAN 发送报文的程序流程说明&#xff0c;结合 HAL 库的使用及代码示例&#xff0c;帮助你了解每一步的具体操作和内部原理。 一、系统与外设初始化 1.1 HAL 库初始化 在 main() 函数开头&#xff0c;首先调用 HAL 库初始化函数&#xff1a; HAL_Init()…

15 数据结构及算法应用

15 数据结构及算法应用 15.1 算法策略区分 15.1.1、分治法 特征:把一个问题拆分成多个小规模的相同子问题&#xff0c;一般可用递归解决。 经典问题:斐波那契数列、归并排序、快速排序、矩阵乘法、二分搜索、大整数乘法、汉诺塔。 15.1.2、贪心法 (一般用于求满意解) …

基于大模型的唇裂手术全流程预测与应用研究报告

目录 一、引言 1.1 研究背景与意义 1.2 研究目标与内容 二、唇裂相关医学知识概述 2.1 唇裂的定义、分类与发病原因 2.2 唇裂对患者生理与心理的影响 2.3 传统唇裂治疗方法与局限性 三、大模型技术原理与应用基础 3.1 大模型概述 3.2 适用于唇裂预测的大模型类型及特…

环境变量设置异常导致UOS文件管理器无法正常运行

编译QT5.15.2&#xff0c;与UOS20.9的QT依赖冲突 现象原因解决方法 现象 重启系统后UOS桌面变成黑色&#xff0c;没有任何图标&#xff0c;任务栏的应用本来是有预览的&#xff0c;但也变得不可用。 原因 找了很久&#xff0c;查到原来是dde-file-manager未能正常启动。直接…

《认知觉醒》改变的核心方法论

《认知觉醒》改变的核心方法论 一、认知觉醒的核心目标 改变 → 提升能力 → 获得更好生活 二、大脑运作机制 脑区运算速度作用特点本能脑1.1亿次/秒自动化反应&#xff0c;能量消耗低情绪脑1.1亿次/秒情感驱动型决策​理智脑​40次/秒战略指挥官角色 关键差异&#xff1a…

Python中的字典:深度解析与应用实践

一、字典的本质与特性 Python字典&#xff08;Dictionary&#xff09;是以**键值对&#xff08;Key-Value Pair&#xff09;**形式存储数据的无序集合&#xff0c;使用大括号{}定义。其核心特性包括&#xff1a; 快速查找&#xff1a;基于哈希表实现&#xff0c;通过键&#…

【蓝桥杯python研究生组备赛】005 数学与简单DP

题目1 01背包 有 N 件物品和一个容量是 V 的背包。每件物品只能使用一次。 第 i 件物品的体积是 vi&#xff0c;价值是 wi。 求解将哪些物品装入背包&#xff0c;可使这些物品的总体积不超过背包容量&#xff0c;且总价值最大。 输出最大价值。 输入格式 第一行两个整数&a…

2024年国赛高教杯数学建模E题交通流量管控解题全过程文档及程序

2024年国赛高教杯数学建模 E题 交通流量管控解题 原题再现 随着城市化进程的加快、机动车的快速普及&#xff0c;以及人们活动范围的不断扩大&#xff0c;城市道路交通拥堵问题日渐严重&#xff0c;即使在一些非中心城市&#xff0c;道路交通拥堵问题也成为影响地方经济发展和…

穿越是时空之门(java)

emm&#xff0c;之前做过一道类似的题目&#xff0c;但是这次又忘了 一开始的错误代码 package Lanqiao;import javax.swing.plaf.synth.SynthTextAreaUI; import java.math.BigInteger;/*** author zb* date2025/3/19 21:33*/ public class L19701 {public static void main…

npm : 无法加载文件 C:\Program Files\nodejs\npm.ps1,因为在此系统上禁止运行脚本的处理方法

1、安装了node.js后&#xff0c;windows powershell中直接输入npm&#xff0c;然后就报错 2、出现原因&#xff1a;权限不够 系统禁用了脚本的执行&#xff0c;所以我们在windows powershell输入npm -v的时候&#xff0c;就会报上面的错误。 3、解决 Set-ExecutionPolicy Un…

蓝桥杯单片机之AT24C02(基于自己对AT24C02的学习和理解)

一、先用抽象法说明原理&#xff0c;让原理变得简单易懂&#xff1a; 1、向AT24C02写入数据&#xff1a; 有个关系户&#xff0c;他想安排自己的儿子进某个大厦里某个楼层的公司&#xff0c;那么他就要先找到这个公司的地址&#xff0c;然后再找到该公司是第几楼&#xff0c;最…

Java面试易忽略知识点

1. CompletableFuture中thenApply()与thenCompose()的区别 考察点&#xff1a;组合式异步编程 解析&#xff1a; ​**thenApply()**&#xff1a;接收前序任务结果&#xff0c;返回普通对象&#xff08;同步转换&#xff09;&#xff0c;适用简单数据处理。​**thenCompose()*…

VLLM专题(十九)—兼容 OpenAI 的服务器

vLLM 提供了一个 HTTP 服务器,能够实现 OpenAI 的 Completions API、Chat API 等功能! 您可以通过 vllm serve 命令启动服务器,或者通过 Docker 启动: vllm serve NousResearch/Meta-Llama-3-8B-Instruct --dtype auto --api-key token-abc123要调用服务器,您可以使用官…

【云原生之kubernetes实战】在k8s环境中高效部署minio对象存储(详细教程)

【云原生之kubernetes实战】在k8s环境中高效部署minio对象存储(详细教程) 前言一、minio介绍1.1 MinIO简介1.2 主要特点1.3 主要使用场景二、相关知识介绍2.1 本次实践存储介绍2.2 k8s存储介绍三、本次实践介绍3.1 本次实践简介3.2 本次环境规划3.3 部署前需准备工作四、检查…

【高项】信息系统项目管理师(八)项目质量管理【3分】

项目质最管理包括把组织的质量政策应用于规划、管理、控制项目和产品质量要求。以满足干系人目标的各个过程。项目质量管理以执行组织的名义支持过程的持续改进活动,项目质量管理需要兼顾项目管理与项目可交付成果两个方面,它适用于所有项目无论项目的可付成果具有何种特性。质…

python-leetcode 48.括号生成

题目&#xff1a; 数字n代表生成括号的对数&#xff0c;设计一个函数&#xff0c;用于生成所有可能并且有效的括号组合。 方法一&#xff1a;回溯 可以生成所有 2**2n 个 ‘(’ 和 ‘)’ 字符构成的序列&#xff0c;然后检查每一个是否有效即可 为了生成所有序列&#xff0c…

TDE透明加密技术:免改造实现华为云ECS中数据库和文件加密存储

在数字经济与云计算深度融合的今天&#xff0c;华为云ECS&#xff08;弹性云服务器&#xff09;已成为企业数字化转型的核心载体&#xff0c;承载着数据库、文件存储、AI训练等关键业务。然而&#xff0c;云上数据安全形势日益严峻&#xff1a;2024年全球云环境勒索攻击同比激增…

3D点云数据处理中的聚类算法总结

1.欧式聚类&#xff1a; 基于点的空间距离&#xff08;欧几里得距离&#xff09;来分割点云&#xff0c;将距离较近的点归为同一簇。 欧式聚类需要的参数&#xff1a;邻域半径R,簇的最小点阈值minPts&#xff0c;最大点数阈值maxPts。 实现效率&#xff1a; O(n * log n) 实现…

PCL--点云可视化

用于单个显示、多个显示的头文件<visual_.h> visual_.h #pragma once #include <iostream> #include <thread> #include <pcl/visualization/pcl_visualizer.h>using namespace std::chrono_literals;/********************************************…