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();
	static
	class 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;
	
	static
	class 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();
	static
	class 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();
	    }
	}
}


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/413001.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

微信小程序蓝牙通信HC08

总结这两天研究的蓝牙串口。人话版资料不多&#xff0c;主要靠翻别人的仓库和文档。 单片机部分&#xff0c;与蓝牙串口通信是通过串口。比我想的要简单&#xff0c;小程序部分&#xff0c;有非常多的服务和特征&#xff0c;而且人话版资料不多。 如果本文有什么问题&#xf…

AI之T2I:Stable Diffusion 3的简介、安装和使用方法、案例应用之详细攻略

AI之T2I&#xff1a;Stable Diffusion 3的简介、安装和使用方法、案例应用之详细攻略 目录 Stable Diffusion 3的简介 1、效果测试 官方demo 网友提供 Stable Diffusion 3的安装和使用方法 1、安装 2、使用方法 Stable Diffusion 3的案例应用 1、基础案例 Stable Diff…

RestTemplate启动问题解决

⭐ 作者简介&#xff1a;码上言 ⭐ 代表教程&#xff1a;Spring Boot vue-element 开发个人博客项目实战教程 ⭐专栏内容&#xff1a;个人博客系统 ⭐我的文档网站&#xff1a;http://xyhwh-nav.cn/ RestTemplate启动问题解决 问题&#xff1a;在SpringCloud架构项目中配…

Vue实现登录保存token并校验实现保存登录状态

文章目录 一、登录vue二、路由index 一、登录vue <script> import request from "/axios/baseURL"; import router from "/router";// 接口数据初始化 const FORM_DATA {userName: "",password: "", }; export default {data(…

腾讯文档(excel也一样)设置单元格的自动行高列宽

1. 选中单元格 可选择任意一个或者几个 2. 设置自动 行高和列宽 即可生效

掌握微信小程序开发的核心要点:从基础到进阶

文章目录 掌握微信小程序开发的核心要点&#xff1a;从基础到进阶一、数据绑定和事件处理1.1 理解小程序的数据绑定机制&#xff0c;实现数据和视图的同步更新1.2 学习如何处理用户交互事件和触发相应的响应逻辑 二、网络请求和数据交互2.1 使用小程序的网络请求API与后端服务器…

unity发布webGL压缩方式的gzip,使用nginx作为web服务器时的配置文件

unity发布webGL压缩方式的gzip&#xff0c;使用nginx作为web服务器时的配置文件 Unity版本是&#xff1a;2021.3 nginx的版本是&#xff1a;nginx-1.25.4 Unity发布webgl时的测试 设置压缩方式是gzip nginx配置文件 worker_processes 1;events {worker_connections 102…

vue项目打包获取git commit信息并输出到打包后的指定文件夹中

需求背景&#xff1a; 前端项目经常打包&#xff0c;发包部署&#xff0c;为了方便测试及运维发现问题时与正确commit信息对比 实现方式&#xff1a; 使用Node.js的child_process模块来执行git命令 实现步骤&#xff1a; 1.在package.json的同级目录下新建一个version.js文件。…

PyQt6的开发流程(密码生成小程序为例)

PyQt6的开发流程&#xff08;密码生成小程序为例&#xff09; 文章目录 PyQt6的开发流程&#xff08;密码生成小程序为例&#xff09;一、流程介绍与概览1. 界面与逻辑分离的开发流程2. PyQt6的开发流程 二、打开 designer.exe 创建文件三、用QT设计师绘制界面保存成ui1. QT常用…

springboot+vue网站开发-后端管理框架-vue-admin-template

为了方便国内用户下载&#xff0c;我把自己的百度网盘分享给大家一份地址&#xff0c;可以去下载。 如果你有上网盒子软件&#xff0c;那就自己去下载&#xff0c;很小。不到1MB. 链接&#xff1a;https://pan.baidu.com/s/15LJ2MoSWToFGFp28VaxBeQ?pwdbaby 提取码&#xff…

微服务-微服务链路追踪组件Skywalking实战

自动化监控系统Prometheus&Grafana实战&#xff1a; 4 trem APM-性能监控项目班&#xff1a; https://vip.tulingxueyuan.cn/detail/p_602e574ae4b035d3cdb8f8fe/6 1. skywalking是什么 1.1 Skywalking主要功能特性 1.2 Skywalking整体架构 1.3 SkyWalking 环境搭建部…

【数据处理】Python解析nii.gz文件

最近又接触了一种影像数据格式&#xff1a;nii.gz文件&#xff0c;记录一下python读取方式。 数据处理系列篇&#xff1a;   【数据处理】Python读取.mat文件的方法   【数据处理】Python读取.dcm文件的方法   【数据处理】Python解析json文件   【数据处理】Python解析…

日更【系统架构设计师知识总结3】存储系统

【原创精华总结】自己一点点手打、总结的脑图&#xff0c;把散落在课本以及老师讲授的知识点合并汇总&#xff0c;反复提炼语言&#xff0c;形成知识框架。希望能给同样在学习的伙伴一点帮助&#xff01;

HTTP与HTTPS-HTTPS 的应用数据是如何保证完整性的?

资料来源 : 小林coding 小林官方网站 : 小林coding (xiaolincoding.com) HTTPS 的应用数据是如何保证完整性的? TLS 在实现上分为握手协议和记录协议两层 TLS 握手协议就是我们前面说的 TLS 四次握手的过程&#xff0c;负责协商加密算法和生成对称密钥&#xff0c;后续用此密…

信息安全计划

任何管理人员或人力资源专业人士都知道&#xff0c;除非彻底记录标准和实践&#xff0c;否则永远无法真正实施和执行标准和实践。正如您可能想象的那样&#xff0c;在保护您的网络、技术和数据系统免受网络威胁以及在发生这些事件时规划最及时、高效和有效的响应时&#xff0c;…

iview碰到的一些问题总结

iview tabs嵌套使用问题 tabs嵌套使用的时候不是直接套用行了&#xff0c;直接套用会出现内层tab都集成到一级tab去&#xff0c;需要设置该属性指向对应 Tabs 的 name 字段(需要版本大于3.3.1) <Tabs name"tab1" ><TabPane label"标签1" tab&qu…

荣耀手机如何开启地震预警功能

1、打开荣耀手机&#xff0c;进入“设置”&#xff0c;在搜素栏输入“地震”。 2、进入“安全-应急预警通知”功能栏。 3、开启“地震预警”。 4、查看“预警演示教程”。 ![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/e207e356bb634c11adf926c6a53e48cc.png…

Git 突破 文件尺寸限制

前言 当Git本地存储里右超过50MB&#xff0c;却又确实需要上传的时候&#xff0c;就需要用到了不是 解决 本代码就是把大文件进行拆解成小文件&#xff0c;然后上传。 等到拉取下来的时候&#xff0c;可以直接再进行合并&#xff0c;合并成原文件 代码如下&#xff0c;仅供…

深度学习基础(一)神经网络基本原理

之前的章节我们初步介绍了机器学习相关基础知识&#xff0c;目录如下&#xff1a; 机器学习基础&#xff08;一&#xff09;理解机器学习的本质-CSDN博客 机器学习基础&#xff08;二&#xff09;监督与非监督学习-CSDN博客 机器学习基础&#xff08;四&#xff09;非监督学…

python Matplotlib Tkinter-->tab切换2

环境 python:python-3.12.0-amd64 包: matplotlib 3.8.2 pillow 10.1.0 import matplotlib.pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk import tkinter as tk import tkinter.ttk as ttk# 创建自定义工具栏类 c…
最新文章