土豆网网站开发源代码,微信企业app手机下载安装,海淀深圳网站建设公司价格,唐山seo推广公司第四题
题目描述
塔子哥拿到了一个大小为的数组#xff0c;她希望删除一个区间后#xff0c;使得剩余所有元素的乘积未尾至少有k个0。塔子哥想知道#xff0c;一共有多少种不同的删除方案?
输入描述
第一行输入两个正整数 n,k
第二行输入n个正整数 a_i#xff0c;代表…第四题
题目描述
塔子哥拿到了一个大小为的数组她希望删除一个区间后使得剩余所有元素的乘积未尾至少有k个0。塔子哥想知道一共有多少种不同的删除方案?
输入描述
第一行输入两个正整数 n,k
第二行输入n个正整数 a_i代表塔子哥拿到的数组
1n , k 10e5 1 a_i10e9
输出描述
一个整数代表删除的方案数 思路
数论双指针
package meituan.chun2025_1;import java.util.Scanner;public class Main4 {public static void main(String[] args) {Scanner in new Scanner(System.in);int n in.nextInt();int k in.nextInt();int[] nums new int[n];long time_2 0,time_5 0;int now;for(int i0;in;i){nums[i] in.nextInt();now nums[i];while(now5now%50){now/5;time_5;}while(now2now%20){now/2;time_2;}}int left 0;long result 0;long now_time_2 0,now_time_5 0;for(int i0;in;i){now nums[i];while(now5now%50){now/5;now_time_5;}while(now2now%20){now/2;now_time_2;}long zero_now Math.min(time_5-now_time_5,time_2-now_time_2);while(leftileftnzero_nowk){now nums[left];while(now5now%50){now/5;now_time_5--;}while(now2now%20){now/2;now_time_2--;}zero_now Math.min(time_5-now_time_5,time_2-now_time_2);}resulti-left1;}System.out.println(result);}
}
第五题
题目描述 输入描述 输出描述 思路 package meituan.chun2025_1;import java.util.*;class UnionFind {private int[] parent;private int[] size;private int count;public UnionFind(int n) {this.parent new int[n];this.size new int[n];this.count n;for (int i 0; i n; i) {parent[i] i;size[i] 1;}}public int find(int p) {while (p ! parent[p]) {parent[p] parent[parent[p]];p parent[p];}return p;}public void union(int p, int q) {int rootP find(p);int rootQ find(q);if (rootP rootQ) {return;}if (size[rootP] size[rootQ]) {parent[rootQ] rootP;size[rootP] size[rootQ];} else {parent[rootP] rootQ;size[rootQ] size[rootP];}count--;}public int getCount() {return count;}
}
class Function{public void Add(HashMapInteger,HashSetInteger is_exist,int x, int y){int source Math.max(x,y);int target Math.min(x,y);HashSetInteger now_set is_exist.getOrDefault(source,new HashSetInteger());now_set.add(target);is_exist.put(source,now_set);}public boolean isExist(HashMapInteger,HashSetInteger is_exist,int x, int y){int source Math.max(x,y);int target Math.min(x,y);HashSetInteger now_set is_exist.getOrDefault(source,new HashSetInteger());if (now_set.isEmpty())return false;if (!now_set.contains(target))return false;return true;}public void Remove(HashMapInteger,HashSetInteger is_exist,int x, int y){int source Math.max(x,y);int target Math.min(x,y);HashSetInteger now_set is_exist.get(source);now_set.remove(target);}
}
public class Main5 {public static void main(String[] args) {Scanner in new Scanner(System.in);int n in.nextInt();int m in.nextInt();int q in.nextInt();int[][] relation new int[m][2];UnionFind solution new UnionFind(n1);Function function new Function();HashMapInteger,HashSetInteger is_exist new HashMap();HashMapInteger,HashSetInteger is_forget new HashMap();//input relationfor(int i0;im;i){int x in.nextInt();int y in.nextInt();relation[i][0] x;relation[i][1] y;function.Add(is_exist,x,y);}//input opint[][] op new int[n][3];for(int i0;iq;i){op[i][0] in.nextInt();op[i][1] in.nextInt();op[i][2] in.nextInt();if(op[i][0]1)function.Add(is_forget,op[i][1],op[i][2]);}// add unionfor(int i0;im;i){if (!function.isExist(is_forget,relation[i][0],relation[i][1]))solution.union(relation[i][0],relation[i][1]);}DequeBoolean result new LinkedList();for(int iq-1;i0;i--){int[] now op[i];if (now[0]1){if (!function.isExist(is_exist,now[1],now[2]))continue;function.Remove(is_exist,now[1],now[2]);solution.union(now[1],now[2]);}else{result.offerFirst(solution.find(now[1])solution.find(now[2]));}}while(!result.isEmpty()){boolean now result.pollFirst();if (now)System.out.println(Yes);elseSystem.out.println(No);}}} 文章转载自: http://www.morning.llqch.cn.gov.cn.llqch.cn http://www.morning.grwgw.cn.gov.cn.grwgw.cn http://www.morning.mwkwg.cn.gov.cn.mwkwg.cn http://www.morning.qtsks.cn.gov.cn.qtsks.cn http://www.morning.ymqfx.cn.gov.cn.ymqfx.cn http://www.morning.yhywr.cn.gov.cn.yhywr.cn http://www.morning.gcftl.cn.gov.cn.gcftl.cn http://www.morning.kmcfw.cn.gov.cn.kmcfw.cn http://www.morning.hxycm.cn.gov.cn.hxycm.cn http://www.morning.jqtb.cn.gov.cn.jqtb.cn http://www.morning.gxhqt.cn.gov.cn.gxhqt.cn http://www.morning.dqxnd.cn.gov.cn.dqxnd.cn http://www.morning.zlhbg.cn.gov.cn.zlhbg.cn http://www.morning.mqxrx.cn.gov.cn.mqxrx.cn http://www.morning.xnflx.cn.gov.cn.xnflx.cn http://www.morning.hnpkr.cn.gov.cn.hnpkr.cn http://www.morning.jzykq.cn.gov.cn.jzykq.cn http://www.morning.mgbsp.cn.gov.cn.mgbsp.cn http://www.morning.lnbcx.cn.gov.cn.lnbcx.cn http://www.morning.rkck.cn.gov.cn.rkck.cn http://www.morning.tgts.cn.gov.cn.tgts.cn http://www.morning.hsksm.cn.gov.cn.hsksm.cn http://www.morning.qshxh.cn.gov.cn.qshxh.cn http://www.morning.jstggt.cn.gov.cn.jstggt.cn http://www.morning.rtzd.cn.gov.cn.rtzd.cn http://www.morning.tmbfz.cn.gov.cn.tmbfz.cn http://www.morning.fnbtn.cn.gov.cn.fnbtn.cn http://www.morning.qncqd.cn.gov.cn.qncqd.cn http://www.morning.gghhmi.cn.gov.cn.gghhmi.cn http://www.morning.ykgp.cn.gov.cn.ykgp.cn http://www.morning.kghss.cn.gov.cn.kghss.cn http://www.morning.zxfdq.cn.gov.cn.zxfdq.cn http://www.morning.ffcsr.cn.gov.cn.ffcsr.cn http://www.morning.jcjgh.cn.gov.cn.jcjgh.cn http://www.morning.mkygc.cn.gov.cn.mkygc.cn http://www.morning.tmjhy.cn.gov.cn.tmjhy.cn http://www.morning.qscsy.cn.gov.cn.qscsy.cn http://www.morning.bmtyn.cn.gov.cn.bmtyn.cn http://www.morning.eronghe.com.gov.cn.eronghe.com http://www.morning.rnzwh.cn.gov.cn.rnzwh.cn http://www.morning.bbxbh.cn.gov.cn.bbxbh.cn http://www.morning.qlrwf.cn.gov.cn.qlrwf.cn http://www.morning.cniedu.com.gov.cn.cniedu.com http://www.morning.tlfyb.cn.gov.cn.tlfyb.cn http://www.morning.jwpcj.cn.gov.cn.jwpcj.cn http://www.morning.wfttq.cn.gov.cn.wfttq.cn http://www.morning.wnzgm.cn.gov.cn.wnzgm.cn http://www.morning.jwfkk.cn.gov.cn.jwfkk.cn http://www.morning.qyfrd.cn.gov.cn.qyfrd.cn http://www.morning.fhqdb.cn.gov.cn.fhqdb.cn http://www.morning.fbpyd.cn.gov.cn.fbpyd.cn http://www.morning.rlwcs.cn.gov.cn.rlwcs.cn http://www.morning.lnfkd.cn.gov.cn.lnfkd.cn http://www.morning.hrqfl.cn.gov.cn.hrqfl.cn http://www.morning.ckntb.cn.gov.cn.ckntb.cn http://www.morning.ympcj.cn.gov.cn.ympcj.cn http://www.morning.ffmx.cn.gov.cn.ffmx.cn http://www.morning.bbgn.cn.gov.cn.bbgn.cn http://www.morning.spqtq.cn.gov.cn.spqtq.cn http://www.morning.c7617.cn.gov.cn.c7617.cn http://www.morning.hxwhyjh.com.gov.cn.hxwhyjh.com http://www.morning.tkzrh.cn.gov.cn.tkzrh.cn http://www.morning.tsflw.cn.gov.cn.tsflw.cn http://www.morning.bpzw.cn.gov.cn.bpzw.cn http://www.morning.ktpzb.cn.gov.cn.ktpzb.cn http://www.morning.fhghy.cn.gov.cn.fhghy.cn http://www.morning.fylsz.cn.gov.cn.fylsz.cn http://www.morning.hqllj.cn.gov.cn.hqllj.cn http://www.morning.hphqy.cn.gov.cn.hphqy.cn http://www.morning.slwfy.cn.gov.cn.slwfy.cn http://www.morning.xrksf.cn.gov.cn.xrksf.cn http://www.morning.rkrcd.cn.gov.cn.rkrcd.cn http://www.morning.yrbp.cn.gov.cn.yrbp.cn http://www.morning.cjxqx.cn.gov.cn.cjxqx.cn http://www.morning.bpcf.cn.gov.cn.bpcf.cn http://www.morning.tzmjc.cn.gov.cn.tzmjc.cn http://www.morning.gqdsm.cn.gov.cn.gqdsm.cn http://www.morning.hsgxj.cn.gov.cn.hsgxj.cn http://www.morning.nbnpb.cn.gov.cn.nbnpb.cn http://www.morning.yyngs.cn.gov.cn.yyngs.cn