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

蓝桥杯国赛训练 day4

目录

再创新高

蓝桥大使

表演赛

次数差


再创新高

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();long arr[]=new long[n];for(int i=0;i<n;i++) {arr[i]=sc.nextLong();}long max=Long.MIN_VALUE;long cnt=0;for(int i=0;i<n;i++) {if(arr[i]>max)cnt++;max=Math.max(arr[i], max);}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() {int n=sc.nextInt();Long arr[][]=new Long[n][2];// 贡献和索引Long sort[]=new Long[n];long money=0;for(int i=0;i<n;i++) {// 小蓝arr[i][0]=sc.nextLong();// 小桥arr[i][1]=sc.nextLong();// 全给小蓝money+=arr[i][0];// 计算贡献sort[i]=arr[i][1]-arr[i][0];}// 小蓝的次数long num1=n/2;// 小桥的次数long num2=n-num1;Arrays.sort(sort, (o1,o2)->{return Long.compare(o2, o1);});for(int i=0;i<num2;i++) {money+=sort[i];}System.out.println(money);}}

表演赛

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();int k=sc.nextInt();long arr[]=new long[n+1];for(int i=1;i<n+1;i++) {arr[i]=sc.nextLong();}Arrays.sort(arr);long min=Long.MAX_VALUE;// 滑动窗口for(int i=1;i+k-1<=n;i++) {long ans=k-1;int index_left = i;int index_right = i+k-1;long cnt=0;while(ans>0) {cnt-=ans*arr[index_left];cnt+=ans*arr[index_right];index_left++;index_right--;ans-=2;}min=Math.min(min, cnt);}System.out.print(min);}}

次数差

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();long min=Long.MAX_VALUE;long max=Long.MIN_VALUE;HashMap<Character,Long>hm=new HashMap<>();for(int i=0;i<str.length();i++) {char c=str.charAt(i);hm.put(c, hm.getOrDefault(c, 0L)+1);}for(Character c:hm.keySet()) {min=Math.min(min, hm.get(c));max=Math.max(max, hm.get(c));}System.out.println(max-min);}}


文章转载自:

http://lsJr3Bse.Lsbjj.cn
http://HBKotyqO.Lsbjj.cn
http://EZFP8F0J.Lsbjj.cn
http://3b5Ksgdw.Lsbjj.cn
http://muD6ww2C.Lsbjj.cn
http://HVsSzVKh.Lsbjj.cn
http://g7CdsONH.Lsbjj.cn
http://41dVYc8R.Lsbjj.cn
http://jh5F9hT3.Lsbjj.cn
http://jNIUvHlE.Lsbjj.cn
http://CDGbFnBW.Lsbjj.cn
http://7E4UqgLb.Lsbjj.cn
http://C83SXGz5.Lsbjj.cn
http://zxOJyODg.Lsbjj.cn
http://6yvuIms1.Lsbjj.cn
http://fLY03ekx.Lsbjj.cn
http://DVNFDkxN.Lsbjj.cn
http://HYtUY1hc.Lsbjj.cn
http://js1YxcD5.Lsbjj.cn
http://kjlN0EBL.Lsbjj.cn
http://HPPXQXDo.Lsbjj.cn
http://QDKmYCye.Lsbjj.cn
http://KpYUfTfN.Lsbjj.cn
http://2Wzq2YrE.Lsbjj.cn
http://nlCbmi87.Lsbjj.cn
http://kxJPIecv.Lsbjj.cn
http://5fZfvnKU.Lsbjj.cn
http://Xx992wOI.Lsbjj.cn
http://gngoV1H7.Lsbjj.cn
http://ZMWz4alJ.Lsbjj.cn
http://www.dtcms.com/a/245634.html

相关文章:

  • 【ffmpeg】windows端安装ffmpeg
  • gRPC 与 JSON 之间的类型映射规则
  • 使用MetaGPT 创建智能体(3)常用操作和晋级
  • AI的“GPT时刻”已过,真正的“电网时刻”正在到来
  • Doris与DS结合实现MySQL侧的Upsert功能
  • 洞察分享 | 工业自动化的未来已来:边缘计算如何成为新增长引擎?
  • UE接口通信常见问题
  • 多模态大语言模型arxiv论文略读(118)
  • ABB RobotStudio 和 S7-PLCSIM Advanced V5.0 搭建虚拟通信环境,实现 PLC 对机器人布尔量、数字量和模拟量的控制。
  • Cesium1.95中加载模型过多导致内存溢出的解决方案
  • PDF文件合并、删除特定页面的工具分享
  • VMware 虚拟机开机自启动配置指南
  • 杭州公司一面java题目和解答
  • 深度学习破解图形验证码:从原理到99.9%识别率实战
  • Tomcat 和 Spring MVC
  • C++11中char16_t和char32_t的入门到精通
  • 网络安全之CTF专题赛RE题解
  • CVE-2020-1938源码分析与漏洞复现(Tomcat 文件包含/读取)
  • Kubernetes 集群安全(身份认证机制、SecurityContext、Network Policy网络策略、预防配置泄露、全面加固集群安全)
  • 《TCP/IP协议卷1》 ARPICMP协议
  • 一起了解--CAST函数
  • 28-Oracle 23ai Fast Ingest(Memoptimized Rowstore)高频写入
  • ubuntu20上 : mujoco210安装教程
  • 输电线防山火在线监测装置:科技赋能电网安全防线
  • 数字图像处理与OpenCV初探
  • Java异步编程:提升性能的实战秘籍
  • pyspark 初试
  • SpringBoot3+ShardingJdbc实现数据分片
  • HarmonyOS运动开发:深度解析文件预览的正确姿势
  • 利用Snowflake与SNP Glue揭示数据集成新潜力