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

HUAWEI Programming Contest 2024(AtCoder Beginner Contest 342)

D - Square Pair

题目大意

  • 给一长为n的数组a,问有多少对A_i,A_j(1\leq i< j\leq n),两者相乘为非负整数完全平方数

解题思路

  • 一个数除以其能整除的最大的完全平方数,看前面有多少个与其余数相同的数,两者乘积满足条件(已经是完全平方数的部分无用)
  • 对于0,特判(与%=0区分开)

import java.io.*;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Vector;public class Main{static long md=(long)998244353;static long Linf=Long.MAX_VALUE/2;static int inf=Integer.MAX_VALUE/2;public static void main(String[] args) throws IOException{AReader input=new AReader();PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));int n=input.nextInt();int[] a=new int[n+1];HashMap<Integer, Integer> hs=new HashMap<Integer, Integer>();long ans=0;for(int i=1;i<=n;++i) {a[i]=input.nextInt();if(a[i]==0) {continue;}int t=a[i];int y=(int)Math.sqrt(a[i]);while(y>0) {int z=y*y;if(t%z==0) {t/=z;break;}y--;}if(hs.get(t)!=null) {int p=hs.get(t);ans+=p;hs.put(t, p+1);}else {hs.put(t, 1);}}int zero=0;for(int i=1;i<=n;++i) {if(a[i]==0) {ans+=i-1;zero++;}else {ans+=zero;}}out.print(ans);out.flush();out.close();}//System.out.println();//out.println();//String o="abcdefghijklmnopqrstuvwxyz";//char[] op=o.toCharArray();staticclass AReader{ BufferedReader bf;StringTokenizer st;BufferedWriter bw;public AReader(){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{//确定下一个token只有一个字符的时候再用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 byte nextByte() throws IOException{return Byte.parseByte(next());}public short nextShort() throws IOException{return Short.parseShort(next());}public BigInteger nextBigInteger() throws IOException{return new BigInteger(next());}public void println() throws IOException {bw.newLine();}public void println(int[] arr) throws IOException{for (int value : arr) {bw.write(value + " ");}println();}public void println(int l, int r, int[] arr) throws IOException{for (int i = l; i <= r; i ++) {bw.write(arr[i] + " ");}println();}public void println(int a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(int a) throws IOException{bw.write(String.valueOf(a));}public void println(String a) throws IOException{bw.write(a);bw.newLine();}public void print(String a) throws IOException{bw.write(a);}public void println(long a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(long a) throws IOException{bw.write(String.valueOf(a));}public void println(double a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(double a) throws IOException{bw.write(String.valueOf(a));}public void print(char a) throws IOException{bw.write(String.valueOf(a));}public void println(char a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}}
}

E - Last Train

题目大意

  • n个点m条边,每条边有信息l,d,k,c

  • 表示l,l+d,l+2*d,\cdots ,l+(k-1)*d时刻有代价为c的路径

  • 1\rightarrow n-1每个点到n的最长距离

解题思路

  •  单一汇点,多源点,反向建图
  • 若当前时间为tim,则到下一个点的时间为may=tim-c
  • 则下一点最晚出发的时间为其等差数列中最大的小于may的时刻
  • 由于有最晚出发时间的限制,所以不会有走环的情况
import java.io.*;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Vector;public class Main{static long md=(long)998244353;static long Linf=Long.MAX_VALUE/2;static int inf=Integer.MAX_VALUE/2;staticclass Edge{int fr,to,nxt;long l,d,k,c;public Edge(int u,int v,long L,long D,long K,long C) {fr=u;to=v;l=L;d=D;c=C;k=K;}}static Edge[] e;static int[] head;static int cnt;static void addEdge(int fr,int to,long l,long d,long k,long c) {cnt++;e[cnt]=new Edge(fr, to, l, d, k, c);e[cnt].nxt=head[fr];head[fr]=cnt;}static class Node{int x;long dis;public Node(int X,long D) {x=X;dis=D;}}public static void main(String[] args) throws IOException{AReader input=new AReader();PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));int n=input.nextInt();int m=input.nextInt();e=new Edge[m+1];head=new int[n+1];cnt=0;for(int i=1;i<=m;++i) {long l=input.nextLong();long d=input.nextLong();long k=input.nextLong();long c=input.nextLong();int u=input.nextInt();int v=input.nextInt();addEdge(v, u, l, d, k, c);}PriorityQueue<Node> q=new PriorityQueue<Node>((o1,o2)->{if(o2.dis-o1.dis>0)return 1;else if(o2.dis-o1.dis<0)return -1;else return 0;});long[] dis=new long[n+1];Arrays.fill(dis, -1);dis[n]=Linf;q.add(new Node(n, Linf));while(!q.isEmpty()) {Node now=q.peek();q.poll();int x=now.x;if(x!=n&&dis[x]>=now.dis)continue;dis[x]=now.dis;for(int i=head[x];i>0;i=e[i].nxt) {int v=e[i].to;long c=e[i].c;long may=dis[x]-c;long l=e[i].l;long d=e[i].d;long k=e[i].k;if(may>=l) {may=l+Math.min((may-l)/d, k-1)*d;q.add(new Node(v, may));}}}for(int i=1;i<n;++i) {if(dis[i]==-1) {out.println("Unreachable");}else out.println(dis[i]);}out.flush();out.close();}//System.out.println();//out.println();staticclass AReader{ BufferedReader bf;StringTokenizer st;BufferedWriter bw;public AReader(){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{//确定下一个token只有一个字符的时候再用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 byte nextByte() throws IOException{return Byte.parseByte(next());}public short nextShort() throws IOException{return Short.parseShort(next());}public BigInteger nextBigInteger() throws IOException{return new BigInteger(next());}public void println() throws IOException {bw.newLine();}public void println(int[] arr) throws IOException{for (int value : arr) {bw.write(value + " ");}println();}public void println(int l, int r, int[] arr) throws IOException{for (int i = l; i <= r; i ++) {bw.write(arr[i] + " ");}println();}public void println(int a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(int a) throws IOException{bw.write(String.valueOf(a));}public void println(String a) throws IOException{bw.write(a);bw.newLine();}public void print(String a) throws IOException{bw.write(a);}public void println(long a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(long a) throws IOException{bw.write(String.valueOf(a));}public void println(double a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(double a) throws IOException{bw.write(String.valueOf(a));}public void print(char a) throws IOException{bw.write(String.valueOf(a));}public void println(char a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}}
}

相关文章:

HUAWEI Programming Contest 2024(AtCoder Beginner Contest 342)

D - Square Pair 题目大意 给一长为的数组&#xff0c;问有多少对&#xff0c;两者相乘为非负整数完全平方数 解题思路 一个数除以其能整除的最大的完全平方数&#xff0c;看前面有多少个与其余数相同的数&#xff0c;两者乘积满足条件&#xff08;已经是完全平方数的部分无…...

Heap sorting

堆排序比较特殊&#xff0c;采用数组表示堆。 先将数组表示成大根堆或者小根堆。然后从堆中依次取根&#xff0c;最后形成有序序列。 #include<bits/stdc.h> using namespace std;const int N 1e5 10; int a[N];void bigheap(int* a, int start, int len) {if(start …...

开源模型应用落地-qwen2模型小试-入门篇(六)

一、前言 经过前五篇“qwen模型小试”文章的学习,我们已经熟练掌握qwen大模型的使用。然而,就在前几天开源社区又发布了qwen1.5版本,它是qwen2模型的测试版本。在基于transformers的使用方式上有较大的调整,现在,我们赶紧跟上脚步,去体验一下新版本模型的推理质量。 二、…...

c#程序,oracle使用Devart驱动解决第第三方库是us7ascii,数据乱码的问题

最近做项目&#xff0c;要跟对方系统的库进行读写&#xff0c;结果发现对方采用的是oracle的us7ascii编码&#xff0c;我们系统默认采用的是ZHS16GBK&#xff0c;导致我们客户端读取和写入对方库的数据都是乱码&#xff0c;搜索网上&#xff0c;发现需要采用独立的oracle驱动去…...

代码随想录算法训练营第四一天 | 背包问题

目录 背包问题01背包二维dp数组01背包一维 dp 数组&#xff08;滚动数组&#xff09;分割等和子集 LeetCode 背包问题 01背包 有n件物品和一个最多能背重量为 w 的背包&#xff0c;第i件物品的重量是weight[i]&#xff0c;得到的价值是value[i] 。每件物品只能用一次&#x…...

AIDL的工作原理与使用示例 跨进程通信 远程方法调用RPC

AIDL的介绍与使用 AIDL&#xff08;Android Interface Definition Language&#xff09;是Android中用于定义客户端和服务端之间通信接口的一种接口定义语言。它允许你定义客户端和服务的通信协议&#xff0c;用于在不同的进程间或同一进程的不同组件间进行数据传递。AIDL通过…...

K8S部署Java项目 pod报错 logs日志内容:no main manifest attribute, in app.jar

天行健&#xff0c;君子以自强不息&#xff1b;地势坤&#xff0c;君子以厚德载物。 每个人都有惰性&#xff0c;但不断学习是好好生活的根本&#xff0c;共勉&#xff01; 文章均为学习整理笔记&#xff0c;分享记录为主&#xff0c;如有错误请指正&#xff0c;共同学习进步。…...

SQL实现模糊查询的四种方法总结

目录 一、一般模糊查询 二、利用通配符查询 1. _ 表示任意的单个字符 2. % 表示匹配任意多个任意字符 3. [ ]表示筛选范围 4. 查询包含通配符的字符串 一、一般模糊查询 1. 单条件查询 //查询所有姓名包含“张”的记录select * from student where name like 张 2. 多条…...

爬虫基本库的使用(urllib库的详细解析)

学习爬虫&#xff0c;其基本的操作便是模拟浏览器向服务器发出请求&#xff0c;那么我们需要从哪个地方做起呢?请求需要我们自己构造吗? 我们需要关心请求这个数据结构怎么实现吗? 需要了解 HTTP、TCP、IP层的网络传输通信吗? 需要知道服务器如何响应以及响应的原理吗? 可…...

【PyQt5桌面应用开发】3.Qt Designer快速入门(控件详解)

一、Qt Designer简介 Qt Designer是PyQt程序UI界面的实现工具&#xff0c;可以帮助我们快速开发 PyQt 程序的速度。它生成的 UI 界面是一个后缀为 .ui 的文件&#xff0c;可以通过 pyiuc 转换为 .py 文件。 Qt Designer工具使用简单&#xff0c;可以通过拖拽和点击完成复杂界面…...

react useMemo 用法

1&#xff0c;useCallback 的功能完全可以由 useMemo 所取代&#xff0c;如果你想通过使用 useMemo 返回一个记忆函数也是完全可以的。 usecallback(fn,inputs)is equivalent to useMemo(()> fn, inputs). 区别是:useCallback不会执行第一个参数函数&#xff0c;而是将它返…...

python学习笔记 - 标准库函数

概述 为了方便程序员快速编写Python脚本程序&#xff0c;Python提供了很多好用的功能模块&#xff0c;它们内置于Python系统&#xff0c;也称为内置函数(Built-in Functions&#xff0c;BlF)&#xff0c;Python 内置函数是 Python 解释器提供的一组函数&#xff0c;无需额外导…...

校招失败后,在小公司熬了 2 年终于进了字节跳动,竭尽全力....

其实两年前校招的时候就往字节投了一次简历&#xff0c;结果很明显凉了&#xff0c;随后这个理想就被暂时放下了&#xff0c;但是这个种子一直埋在心里这两年除了工作以外&#xff0c;也会坚持写博客&#xff0c;也因此结识了很多优秀的小伙伴&#xff0c;从他们身上学到了特别…...

PYTHON-使用正则表达式进行模式匹配

目录 Python 正则表达式Finding Patterns of Text Without Regular ExpressionsFinding Patterns of Text with Regular ExpressionsCreating Regex ObjectsMatching Regex ObjectsReview of Regular Expression MatchingMore Pattern Matching with Regular ExpressionsGroupi…...

Fiddler工具 — 19.Fiddler抓包HTTPS请求(二)

5、查看证书是否安装成功 方式一&#xff1a; 点击Tools菜单 —> Options... —> HTTPS —> Actions 选择第三项&#xff1a;Open Windows Certificate Manager打开Windows证书管理器。 打开Windows证书管理器&#xff0c;选择操作—>查看证书&#xff0c;在搜索…...

架构设计:流式处理与实时计算

引言 随着大数据技术的不断发展&#xff0c;流式处理和实时计算在各行各业中变得越来越重要。那么什么是流式处理呢&#xff1f;我们又该怎么使用它&#xff1f;流式处理允许我们对数据流进行实时分析和处理&#xff0c;而实时计算则使我们能够以低延迟和高吞吐量处理数据。本…...

Linux系统安装zookeeper

Linux安装zookeeper 安装zookeeper之前需要安装jdk&#xff0c;确认jdk环境没问题之后再开始安装zookeeper 下载zookeeper压缩包&#xff0c;官方下载地址&#xff1a;Apache Download Mirrors 将zookeeper压缩包拷贝到Linux并解压 # (-C 路径)可以解压到指定路径 tar -zxv…...

【前端素材】推荐优质后台管理系统Modernize平台模板(附源码)

一、需求分析 后台管理系统是一种用于管理和控制网站、应用程序或系统后台操作的软件工具&#xff0c;通常由授权用户&#xff08;如管理员、编辑人员等&#xff09;使用。它提供了一种用户友好的方式来管理网站或应用程序的内容、用户、数据等方面的操作&#xff0c;并且通常…...

二、Vue组件化编程

2、Vue组件化编程 2.1 非单文件组件 <div id"root"><school></school><hr><student></student> </div> <script type"text/javascript">//创建 school 组件const school Vue.extend({template: <div&…...

JVM跨代引用垃圾回收

1. 跨代引用概述 在Java堆内存中&#xff0c;年轻代和老年代之间存在的对象相互引用&#xff0c;假设现在要进行一次新生代的YGC&#xff0c;但新生代中的对象可能被老年代所引用的&#xff0c;为了找到新生代中的存活对象&#xff0c;不得不遍历整个老年代。这样明显效率很低…...

选吉他不踩坑:合板、单板、全单材质深度解析,新手看懂这篇就够

对于新手来说&#xff0c;挑选吉他时最容易被“合板”“单板”“全单”这些专业术语绕晕。其实&#xff0c;这三者的核心区别在于木材的构成方式&#xff0c;而木材直接决定了吉他的音色、手感以及使用寿命。今天我们就抛开品牌干扰&#xff0c;纯科普这三种材质的底层逻辑&…...

Python3与pysoem实战:基于SDO的EtherCAT伺服电机多模式控制

1. 环境准备与基础配置 在开始EtherCAT伺服电机控制之前&#xff0c;我们需要搭建一个稳定的开发环境。我推荐使用Ubuntu 20.04 LTS作为基础系统&#xff0c;这个版本对Python3和网络驱动的支持都非常完善。在实际项目中&#xff0c;我发现普通用户权限往往无法直接操作网卡设备…...

LiuJuan Z-Image Generator参数详解:CFG Scale=2.0与12步生成高质量人像

LiuJuan Z-Image Generator参数详解&#xff1a;CFG Scale2.0与12步生成高质量人像 想用AI生成一张惊艳的人像照片&#xff0c;却发现要么细节模糊&#xff0c;要么风格怪异&#xff0c;怎么调参数都达不到理想效果&#xff1f;如果你也遇到过类似问题&#xff0c;那今天这篇文…...

ofa_image-caption生产环境部署:支持批量图片处理与结果导出的企业方案

ofa_image-caption生产环境部署&#xff1a;支持批量图片处理与结果导出的企业方案 1. 项目背景与核心价值 在实际的企业应用中&#xff0c;图像内容理解已经成为许多业务场景的必备能力。无论是电商平台的商品图片描述生成&#xff0c;还是内容平台的海量图片标注&#xff0…...

3种策略实现百度网盘提取码智能解析效率提升85%

3种策略实现百度网盘提取码智能解析效率提升85% 【免费下载链接】baidupankey 项目地址: https://gitcode.com/gh_mirrors/ba/baidupankey 副标题&#xff1a;分布式检索技术突破与资源获取效率革命 核心痛点&#xff1a;为何获取提取码成为数字资源流通的主要瓶颈&am…...

QRazyBox:5分钟解决二维码修复难题的专业工具

QRazyBox&#xff1a;5分钟解决二维码修复难题的专业工具 【免费下载链接】qrazybox QR Code Analysis and Recovery Toolkit 项目地址: https://gitcode.com/gh_mirrors/qr/qrazybox 二维码已经成为现代生活中无处不在的数字桥梁&#xff0c;但你是否遇到过这样的情况&…...

如何快速解锁原神60帧限制:免费开源工具终极指南

如何快速解锁原神60帧限制&#xff1a;免费开源工具终极指南 【免费下载链接】genshin-fps-unlock unlocks the 60 fps cap 项目地址: https://gitcode.com/gh_mirrors/ge/genshin-fps-unlock 想要在《原神》中体验120帧甚至更高帧率的流畅游戏画面吗&#xff1f;genshi…...

Comsol异构电池力电热耦合模型:探索电池的多场奥秘

comsol异构电池力电热耦合模型 采用椭圆型电极颗粒模拟锂离子正负极的电极颗粒&#xff0c;还原真实电池的3D介观结构&#xff0c;耦合电化学场-热场-力学场&#xff0c;可模拟电流&#xff0c;浓度&#xff0c;温度&#xff0c;应力等多场结果在电池研究领域&#xff0c;深入理…...

半导体晶圆测量中的5大常见误区:从台阶仪到无图晶圆系统的避坑指南

半导体晶圆测量中的5大常见误区&#xff1a;从台阶仪到无图晶圆系统的避坑指南 在半导体制造领域&#xff0c;晶圆测量是确保器件性能与良率的关键环节。然而&#xff0c;即使是经验丰富的工程师&#xff0c;也常因忽视某些细节而陷入测量陷阱。本文将揭示五个最具隐蔽性的操作…...

RRT*在ROS中的实战:用Gazebo仿真实现动态避障(Python+ROS Noetic)

RRT*在ROS中的实战&#xff1a;用Gazebo仿真实现动态避障&#xff08;PythonROS Noetic&#xff09; 路径规划是机器人自主导航的核心技术之一。在复杂动态环境中&#xff0c;如何快速找到一条安全且优化的路径一直是研究热点。RRT*&#xff08;Rapidly-exploring Random Trees…...