代码编织梦想

1.连号区间数(枚举💡skill)

在这里插入图片描述

思路:
小技巧:如果在区间[L,R]中,maxnn-minnR-L,则说明[L,R]区间的数是递增的。
很多时候都会用到
对于此题,我们只需要枚举l.r判断是否满足此关系式即可。如果满足那么这个区间的数排序后肯定是递增且连续的。


public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	static int N = 10010;
	static int[] a= new int[N];
	static int n = 0,ans = 0;
	public static void main(String[] args) throws Exception{
		n = Integer.parseInt(br.readLine());
		String[] aa = br.readLine().split(" ");
		for(int i = 1; i <= n; i++) {
			a[i] = Integer.parseInt(aa[i - 1]);
		}
		for(int i = 1; i <= n; i++) {
			int maxn = a[i];
			int minn = a[i];
			for(int j = i; j <= n; j++) {
				maxn = Math.max(maxn, a[j]);
				minn = Math.min(minn,a[j]);
				if(j - i == maxn - minn) {
					ans++;
				}
			}
		}
		out.println(ans);
		out.flush();
	}
}

2.递增三元组(❤️前缀和/二分❤️)

在这里插入图片描述
💡💡💡法1:前缀和
借助B当作中间数,查找A中有多少个比B小的,C中有多少个比B大的;
我们需要记住A和C中每个数字出现的次数,采用num_a,num_c表示每个数出现的次数。
借助临时数组s[]表示所有数出现次数的前缀和。sum_a[]表示A的前缀和,sum_c[]表示c的前缀和

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	static int N = 100010;
	static int[] a= new int[N];
	static int[] b= new int[N];
	static int[] c= new int[N];
	static int[] num_a= new int[N];
	static int[] num_c= new int[N];
	static int[] sum_a= new int[N];
	static int[] sum_c= new int[N];
	static int[] s = new int[N];
	static int n = 0;
	static long ans = 0;
	public static void main(String[] args) throws Exception{
		input();

		for(int i = 1; i < N; i++) {
			s[i] = s[i - 1] + num_a[i];//a中1-i所有数出现的总数
		}
		for(int i = 1; i <= n; i++) {
			sum_a[i] = s[b[i] - 1]; //小于bi的数有多少个
		}
		
		Arrays.fill(s, 0);
		
		for(int i = 1; i < N; i++) {//注意此时的数据范围
			s[i] = s[i - 1] + num_c[i];//a中1-i所有数出现的总数
		}
		for(int i = 1; i <= n; i++) {
			sum_c[i] = s[N - 1] - s[b[i]]; //大于b[i]的数有多少个
		}
		
		for(int i = 1; i <= n;i++) {
			ans = ans + (long)sum_a[i] * sum_c[i];
		}
		out.println(ans);
		out.flush();
	}
	
	private static void input() throws Exception, Exception {
		n = Integer.parseInt(br.readLine());
		String[]aa = br.readLine().split(" ");
		for(int i = 1; i <= n; i++) {
			a[i] = Integer.parseInt(aa[i - 1]) + 1;
			num_a[a[i]]++;
		}
		String[]bb = br.readLine().split(" ");
		for(int i = 1; i <= n; i++) {
			b[i] = Integer.parseInt(bb[i - 1]) + 1;
		}
		String[]cc = br.readLine().split(" ");
		for(int i = 1; i <= n; i++) {
			c[i] = Integer.parseInt(cc[i - 1]) + 1;
			num_c[c[i]]++;
		}
	}
}

💡💡💡法2:二分
依旧是以B为分割点,将A和C数组排序,此时满足单调性,我们在A中找小于target的最后一个,在C中找大于target的第一个(后面的元素肯定都是大于target的)然后相乘即可。

public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	static int N = 100010;
	static int[] a= new int[N];
	static int[] b= new int[N];
	static int[] c= new int[N];
	static int[] num_a= new int[N];
	static int[] num_c= new int[N];
	static int[] sum_a= new int[N];
	static int[] sum_c= new int[N];
	static int[] s = new int[N];
	static int n = 0;
	static long ans = 0;
	public static void main(String[] args) throws Exception{
		input();
		Arrays.sort(a,1,1+n);
		Arrays.sort(c,1,1+n);
		for(int i = 1; i <= n; i++) {
			int target = b[i];
			int la = findLess(target);
			int lc = findMore(target);
//			System.out.println(la +" " +lc);
			ans = ans + (long)la*lc;
		}
		System.out.println(ans);
	}
	//找大于的第一个
	private static int findMore(int target) {
		int l = 1, r = n;
		int res = -1;
		while(l <= r) {
			int mid = (l + r) >> 1;
			if(c[mid] > target) {
				res = mid;
				r = mid - 1;
			}else {
				l = mid + 1;
			}
		}
		if(res == -1) {
			return 0;
		}else {
			return (n - res + 1);
		}
	}
	//找小于的最后一个
	private static int findLess(int target) {
		int l = 1, r = n;
		int res = -1;
		while(l <= r) {
			int mid = (l +r) >> 1;
			if(a[mid] < target) {
				res = mid;
				l = mid + 1;
			}else {
				r = mid - 1;
			}
		}
		if(res == -1) {
			return 0;
		}else {
			return res;
		}
	}

	private static void input() throws Exception, Exception {
		n = Integer.parseInt(br.readLine());
		String[]aa = br.readLine().split(" ");
		for(int i = 1; i <= n; i++) {
			a[i] = Integer.parseInt(aa[i - 1]);
		}
		String[]bb = br.readLine().split(" ");
		for(int i = 1; i <= n; i++) {
			b[i] = Integer.parseInt(bb[i - 1]);
		}
		String[]cc = br.readLine().split(" ");
		for(int i = 1; i <= n; i++) {
			c[i] = Integer.parseInt(cc[i - 1]);
		}
	}
}

3.特别数的和(模拟)

在这里插入图片描述
很简单,n很小直接取出n的每一位去判断即可。


public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	static int n = 0;
	static long ans = 0;
	public static void main(String[] args) throws Exception{
		n = Integer.parseInt(br.readLine());
		for(int i = 1; i <= n; i++) {
			if(check(i)) {
				ans = ans + (long)i;
			}
		}
		System.out.println(ans);
		
	}
	private static boolean check(int x) {
		while(x != 0) {
			int t = x%10;
			if(t == 2 || t == 0 || t == 1 || t == 9) {
				return true;
			}
			x/=10;
		}
		return false;
	}
}

在这里插入图片描述
思路:直接记录每个数字出现的次数,在最大值和最小值之间出现2次的肯定是重号,出现0次的肯定是断号。

public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	static int n = 0;
	static long ans = 0;
	static int minn = (int) (1e5 + 10),maxn = -1;
	static int[] count = new int[100010];
	public static void main(String[] args) throws Exception{
		int t = Integer.parseInt(br.readLine());
		while(t-- > 0) {
			
//			Arrays.fill(count, 0);
			String[] aa = br.readLine().split(" ");
			for(int i = 0; i < aa.length; i++) {
				int num = Integer.parseInt(aa[i]);
				maxn = Math.max(maxn, num);
				minn = Math.min(minn,num);
				count[num]++;
			}
		}
		int c = 0,d = 0;
		for(int i = minn; i <= maxn; i++) {
			if(count[i] == 2) {
				c = i;
			}
			if(count[i] == 0) {
				d = i;
			}
		}
		out.println(d + " " + c);
		out.flush();
	}
}

4.回文日期(枚举/LocalDate👍)

在这里插入图片描述
在这里插入图片描述

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.time.LocalDate;
import java.util.Arrays;

public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	static int n = 0;
	static long ans = 0;
	public static void main(String[] args) throws Exception{
		String str1 = br.readLine();
		int y1 = Integer.parseInt(str1.substring(0,4));
		int m1 = Integer.parseInt(str1.substring(4,6));
		int d1 = Integer.parseInt(str1.substring(6,8));
		String str2 = br.readLine();
		int y2 = Integer.parseInt(str2.substring(0,4));
		int m2 = Integer.parseInt(str2.substring(4,6));
		int d2 = Integer.parseInt(str2.substring(6,8));
		LocalDate t1= LocalDate.of(y1, m1, d1);//创建指定日期的LocalDate
		LocalDate t2= LocalDate.of(y2, m2, d2);
		while(!t1.isEqual(t2)) {
			String t = t1.toString();
			if(check(t)) {
				ans++;
			}
			t1 = t1.plusDays(1); //向后跳转1天
		}
		String t = t1.toString();
		//需要注意当两天重合的时候,需要判断一下
		if(check(t)) {
			ans++;
		}
		System.out.println(ans);
	}
	private static boolean check(String t) {
		//String类型可以保存前导0,如果转为数字再操作的话可能丢失前导0
		String[]x = t.split("-");
		String t1 = x[0] + x[1] + x[2];
//		System.out.println(t1);
		StringBuilder t2 = new StringBuilder(t1);
		t2.reverse(); 
		String t3 = t2.toString();//必须采用String类型的变量来接收
		if(t1.equals(t3)) {
			return true;
		}
		return false;
	}
}


5.归并排序

在这里插入图片描述


public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	static int N = (int) (1e5 + 10);
	static int[]is1 = new int[N];
	static int[]is2 = new int[N];
	static int n = 0;
	public static void main(String[] args) throws Exception{
		n = Integer.parseInt(br.readLine());
		String[] aa = br.readLine().split(" ");
		for(int i = 1; i <= n; i++) {
			is1[i] = Integer.parseInt(aa[i - 1]);
		}
		mergesort(1,n);
		for(int i = 1; i <= n; i++) {
			System.out.print(is1[i] + " ");
		}
	}
	private static void mergesort(int l, int r) {
		if(l >= r)return;
		int mid = (l + r) /2 ;
		mergesort(l, mid);
		mergesort(mid + 1, r);
		merge(l,mid,r);
	}
	private static void merge(int l, int mid, int r) {
		int i = l,j = mid + 1, k = l;
		while(i <= mid && j <= r) {
			if(is1[i] < is1[j]) {
				is2[k++] = is1[i++];
			}else {
				is2[k++] = is1[j++];
			}
		}
		while(i <= mid) {
			is2[k++] = is1[i++];
		}
		while(j <= r) {
			is2[k++] = is1[j++];
		}
		for(i = l; i <= r; i++) {
			is1[i] = is2[i];
		}
	}

}

6.移动距离(模拟/new💡)

在这里插入图片描述
思路:
两个楼之间的最短距离就是曼哈顿距离,很明显我们需要找出m和n的坐标,对宽度w取模我们可以得到行号,列号的话与所在行的奇偶有关,奇数行是正序,偶数行是逆序的(画个图理解一下)就可以找到

public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	static int n = 0,w = 0, m = 0;
	public static void main(String[] args) throws Exception{
		String[] wmn = br.readLine().split(" ");
		boolean rev = false;
		w = Integer.parseInt(wmn[0]);
		m = Integer.parseInt(wmn[1]);
		n = Integer.parseInt(wmn[2]);
		int fir[] = count(m);
		int sec[] = count(n);
		System.out.println(Math.abs(fir[0]-sec[0]) + Math.abs(fir[1] - sec[1]));
	}
	
	static int[] count(int x) {
	    //temp[0]是行号,temp[1]是列号
	    int []temp = new int[2];
	    int mod = x % w; //列号
	    if(x%w == 0){
	        temp[0] = x/w;
	    }else{
	        temp[0] = x/w + 1;
	    }
	    int p = temp[0] % 2;//记录行号的奇偶
	    if(p == 1){
	        if(mod==0){
	            temp[1] = w;
	        }else{
	            temp[1] = mod;
	        }
	    }else{
	        if(mod == 0){
	            temp[1] = 1;
	        }else{
	            temp[1] = w - mod + 1;
	        }
	    }
	    return temp;
	}
}

7.日期问题

在这里插入图片描述
思路:现在给定范围内进行枚举,然后判断是否为合法日期,最后看是否与所给的数相匹配,我们枚举的时候就已经实现了按照升序排序。

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	static int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	static int n = 0,w = 0, m = 0;
	static int a = 0, b = 0, c = 0;
	public static void main(String[] args) throws Exception{
		String[]d = br.readLine().split("/");
		a = Integer.parseInt(d[0]);
		b = Integer.parseInt(d[1]);
		c = Integer.parseInt(d[2]);
		
		for(int i = 19600101; i <= 20591231;i ++) {
			int year = i / 10000, month = i % 10000 / 100,day = i % 100;
			if(check(year,month,day)) {
				if(com(year%100,month,day)||com(month,day,year%100)||com(day,month,year%100)) {
					out.printf("%d-%02d-%02d\n",year,month,day);
				}
			}
		}
		out.flush();
		out.close();
	}
	private static boolean check(int year, int month, int day) {
		if(month == 0 || month > 12) {return false;}
		if(day == 0) {return false;}
		if(((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))){
		    days[2] = 29;
		}
		else {
			days[2] = 28;
		}
		if(day > days[month]) {
			return false;
		}
		return true;
	}
	private static boolean com(int year, int month, int day) {
		if(year == a && month == b && day == c) {
			return true;
		}
		return false;
	}
	
}

8.航班时间(转换题意)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
思路:因为保证飞行时间不超过24小时,所以d一定是1位数。
本题的难点主要是转换题意,因为题意比较抽象,代码实现并不难(一般此时我们需要借助数学的思想去转换题意)

我们可以得出:
(1)去程起飞时间+飞行时间x+时差=去程降落时间;
(2)返程起飞时间+飞行时间x-时差=返程降落时间;
我们需要求的是飞行时间x(1)+(2)得到:
去程起飞时间+2*飞行时间x+返程起飞时间=去程降落时间+返程降落时间;
x=((去程降落时间-去程起飞时间)+(返程降落时间-返程起飞时间))/2

下面直接根据公式进行计算就可以了。

public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	static int n = 0,w = 0, m = 0;
	static int a = 0, b = 0, c = 0;
	public static void main(String[] args) throws Exception{
		int t = Integer.parseInt(br.readLine());
		while(t-- > 0) {
			String[] go = br.readLine().split(" ");
			String[] back = br.readLine().split(" ");
			int d1 = 0,d2 = 0;
			String[]g1 = go[0].split(":");//去升的时间
			String[]b1 = go[1].split(":");//去降的时间
			String[]g2 = back[0].split(":");//回来升的时间
			String[]b2 = back[1].split(":");//回来降的时间
			if(go.length == 3) {
				d1 = go[2].charAt(2) - '0';
			}
			if(back.length == 3) {
				d2 = back[2].charAt(2) - '0';
			}
			int ans1 = get_seconds(b1,d1) - get_seconds(g1,0);
			int ans2 = get_seconds(b2,d2) - get_seconds(g2,0);
			int ans = (ans1 + ans2)/2;
			int hh = ans/3600;
			int mm = ans%3600/60;
			int ss = ans % 60;
			System.out.printf("%02d:%02d:%02d\n",hh,mm,ss);
		}
	}
	private static int get_seconds(String[] t, int d1) {
		int tol = 0;
		int h = Integer.parseInt(t[0]);
		int min = Integer.parseInt(t[1]);
		int sed = Integer.parseInt(t[2]);
		tol = d1*24*60*60 + h *60 * 60 + min*60 + sed;
		return tol;
	}
	
}

9.外卖店优先级(模拟)

在这里插入图片描述
在这里插入图片描述

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;

public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	static int N = (int) (1e5 + 100);
	static boolean[] ok = new boolean[N];
	static int[] last = new int[N];
	static int[] lev = new int[N];
	static PII[] info = new PII[N];
	static int n = 0,t = 0, m = 0;
	static int a = 0, b = 0, c = 0;
	public static void main(String[] args) throws Exception{
		String []nmt = br.readLine().split(" ");
		n = Integer.parseInt(nmt[0]);
		m = Integer.parseInt(nmt[1]);
		t = Integer.parseInt(nmt[2]);

		for(int i = 1; i <= m;i++) {
			String[] xy = br.readLine().split(" ");
			int ts = Integer.parseInt(xy[0]);
			int id = Integer.parseInt(xy[1]);
			info[i] = new PII(ts,id);
		}
		Arrays.sort(info,1,m + 1, new cmp());
		for(int i = 1; i <= m;i++) {
			int ts = info[i].ts;
			int ver = info[i].id;
			if(ts > t) {
				break;
			}
			if(ts == last[ver]) {
				lev[ver] += 2;
				last[ver] = ts;
			}else {
				lev[ver] += (ts - last[ver] - 1) * (-1);
				if(lev[ver] < 0) {lev[ver] = 0;}
				if (lev[ver] <= 3) {ok[ver] = false;}
				lev[ver] += 2;
				last[ver] = ts;
			}
			if(lev[ver] > 5) {
				ok[ver] = true;
			}
		}
		for(int i = 1; i <= n; i++) {
			if(last[i] < t) {
				lev[i] += (t - last[i])*(-1);
				if (lev[i] < 0) {
					lev[i] = 0;
				}
				if(lev[i] > 5) {
					ok[i] = true;
				}
				if(lev[i] <= 3) {
					ok[i] = false;
				}
			}
		}
		int ans = 0;
		for(int i = 1; i <= n; i++) {
			if(ok[i]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

class PII{
	public PII(int ts, int id) {
		this.ts = ts;
		this.id = id;
	}
	int ts,id;
}
class cmp implements Comparator<PII>{
	public int compare(PII o1, PII o2) {
		return o1.ts - o2.ts;
	}
	
}

10.逆序对的数量

在这里插入图片描述

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;

public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	static int N = (int) (1e5 + 10);
	static int[]is1 = new int[N];
	static int[]is2 = new int[N];
	static int n = 0,ans = 0;
	public static void main(String[] args) throws Exception{
		n = Integer.parseInt(br.readLine());
		String[] aa = br.readLine().split(" ");
		for(int i = 1; i <= n; i++) {
			is1[i] = Integer.parseInt(aa[i - 1]);
		}
		mergesort(1,n);
//		for(int i = 1; i <= n; i++) {
//			System.out.print(is1[i] + " ");
//		}
		System.out.println(ans);
	}
	private static void mergesort(int l, int r) {
		if(l >= r)return;
		int mid = (l + r) /2 ;
		mergesort(l, mid);
		mergesort(mid + 1, r);
		merge(l,mid,r);
	}
	private static void merge(int l, int mid, int r) {
		int i = l,j = mid + 1, k = l;
		while(i <= mid && j <= r) {
			if(is1[i] <= is1[j]) {
				is2[k++] = is1[i++];
			}else {
				//is[]和is[]均为有序序列
				//如果a[i] > a[j]那么[i,mid]的数全都大于j
				is2[k++] = is1[j++];
				//此处记录逆序对的对数
				ans += (mid - i + 1);
			}
		}
		while(i <= mid) {
			is2[k++] = is1[i++];
		}
		while(j <= r) {
			is2[k++] = is1[j++];
		}
		for(i = l; i <= r; i++) {
			is1[i] = is2[i];
		}
	}

}

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_52986400/article/details/129616639

模拟(枚举)-第四届蓝桥杯省赛C++B组-连号区间数-爱代码爱编程

模拟(枚举)-第四届蓝桥杯省赛C++B组-连号区间数 题目: 小明这些天一直在思考这样一个奇怪而有趣的问题: 在 1∼N 的某个排列中有多少个连号区间呢? 这里所说的连号区间的定义是: 如果区间 [L,R] 里的所有元素(即此排列的第 L 个到第 R 个元素)递增排序后能得到一个长度为 R−L+1 的“连续”数列,则称这个区间连号区间。 当 N

2021算法竞赛入门班第一节课枚举贪心习题-爱代码爱编程

枚举贪心 题单链接 枚举常用算法:前缀和,差分数组,双指针(尺取法)。 文章目录 枚举贪心各题题解1. Flip Game2. Subsequence3.Quasi Binary4.Protecting the Flowers5.校门外的树6.明明的随机数7.[HNOI2003]激光炸弹8.铺地毯9.纪念品分组10.回文日期11.拼数12.毒瘤xo

枚举&模拟-爱代码爱编程

枚举&模拟 模拟 1210. 连号区间数 二重循环枚举所有子区间,然后sort,然后判断是否符合条件(满足max-min=b-a),这个判断条件是要想清楚的 #include<iostream> #include<algorithm> using namespace std; const int N =

专题(四) 枚举模拟排序 ——AcWing 466. 回文日期-爱代码爱编程

【题目描述】 AcWing 466. 回文日期 【思路】 回文日期 枚举 闰年 1 3 5 7 8 10 12 31天永不差 2 28/29 4 6 9 11 30天 智障 第一想法居然是去枚举所有合法日期然后判断是否是回文数 8位数的日期 只需枚举前四位年份 然后构造回文 判断该回文是否是真实存在 这样只需枚举 1000~9999 总共9k个数 i

2022蓝桥杯学习——4.枚举、模拟与排序-爱代码爱编程

一、枚举 蓝桥杯真题 1.连号区间 题目描述 小明这些天一直在思考这样一个奇怪而有趣的问题: 在 1∼N 的某个排列中有多少个连号区间呢? 这里所说的连号区间的定义是: 如果区间 [L,R] 里的所有元素(即此排列的第 L 个到第 R 个元素)递增排序后能得到一个长度为 R−L+1 的“连续”数列,则称这个区间连号区间。 当 N 很小的时候,

备战蓝桥杯-枚举、排序、模拟专项练习详解(含有多道蓝桥杯原题)-爱代码爱编程

枚举、模拟与排序 蓝桥杯所有专项练习 蓝桥杯原题: 连号区间数 小明这些天一直在思考这样一个奇怪而有趣的问题: 在 1∼N1∼N 的某个排列中有多少个连号区间呢? 这里所说的连号区间的定义是: 如果区间 [L,R][L,R] 里的所有元素(即此排列的第 LL 个到第 RR 个元素)递增排序后能得到一个长度为 R−L+1R−L+1 的“连续”数列

【蓝桥杯】枚举,模拟,排序专题 (一)-爱代码爱编程

🏠:博客首页: 进击的波吉 📕:今日分享的文章: 【蓝桥杯】枚举,模拟,排序专题 (一) 💝:坚持刷力扣,分享前三题题解🎈 🌱:Boji 还在努力学算法 ,如有疑问、疏漏之处,请多多指点🙏 ☀️:自学成长的路上,感谢大家相伴!No hurry , No Pause !💝 开篇分享 ⭐️距离蓝桥杯开赛不到两个月,将Acwing蓝桥杯分类专题的题

[AcWing蓝桥杯]之枚举,模拟与排序(C++题解)-爱代码爱编程

目录 连号区间数 递增三元组(枚举+二分+前缀和) 二分法:O(N*logN) 前缀和:O(N)!!! 特别数的和(特别简单) 错误票据 回文日期 移动距离 日期问题 航班时间 外卖店优先级 归并排序(模板) 逆序对的数量(归并排序的应用)(待回看) 连号区间数 1210. 连号区间数 - AcWing题库

枚举+模拟+排序-爱代码爱编程

我是目录 枚举+模拟+排序枚举连号区间数递增三元组二分双指针前缀和模拟特别数的和错误票据排序快速排序归并排序 枚举+模拟+排序 枚举和模拟其实是没什么算法可言的,大多数都是按照题目意思去写,这里提供快排和归并的两个模板。 枚举 连号区间数 来源:第四届蓝桥杯省赛C++B组,第四届蓝桥杯省赛JAVAB组 小明这些天一直在思考这样一个奇怪

蓝桥杯 --- 枚举、模拟与排序-爱代码爱编程

蓝桥杯 --- 枚举、模拟与排序 枚举1210. 连号区间数(枚举 + 优化)1236. 递增三元组(前缀和 + 枚举)1245. 特别数的和(枚举)模拟1204. 错误票据(模拟 + 排序)466. 回文日期(模拟 + 枚举)排序787. 归并排序(排序) 枚举 1210. 连号区间数(枚举 + 优化) 小明这些天一直在思考这样一个奇怪而

蓝桥杯AcWing 题目题解 - 枚举、模拟与排序-爱代码爱编程

目录 AcWing 1210. 连号区间数 AcWing 1236. 递增三元组 AcWing 1204. 错误票据  AcWing 466. 回文日期 AcWing 1219. 移动距离 AcWing 1229. 日期问题 AcWing 1231. 航班时间  小知识:sscanf函数用法 AcWing 1210. 连号区间数 小明这

java习题——集合类、枚举类型与泛型——英文字母输出,掷骰子,彩虹枚举,体检记录模拟_山河之书liu_zixin的博客-爱代码爱编程

1、使用数组和ArrayList类,先输出A→Z,再输出z→a import java.util.*; public class CharacterPrinter { public static void main(String[] args) { char[] upper_array = new char[26]; char[] lower

第十四届蓝桥杯模拟赛(第二期)_正在黑化的ks的博客-爱代码爱编程

写在前面  包含本次模拟赛的10道题题解能过样例,应该可以AC若有错误,欢迎评论区指出有疑问可私信我哈🫰🏻   从2023开始暴力枚举每一个数,直到找到正确答案  start = 2022 def check(num) : t = str(bin(num)) if t[-6:] == '000000' :

蓝桥杯第十四届蓝桥杯模拟赛第三期考场应对攻略(c/c++)-爱代码爱编程

这里把我的想法和思路写出来,恳请批评指正! 目录 考前准备 试题1: 试题2: 试题3: 试题4: 试题5: 试题6: 试题7: 试题8: 试题9: 试题10: 总结: 考前准备 考前五分钟,开十个源文件,并把头文件等必须写的部分写出来,写完的程序一定要有顺序地保留 试题1: 问题描述 请找到一个大于 2022 的最小数

[蓝桥杯] 枚举、模拟和排列问题_排序在蓝桥杯中的应用-爱代码爱编程

  文章目录 一、连号区间数  1、1 题目描述 1、2 题解关键思路与解答 二、递增三元组 2、1 题目描述 2、2 题解关键思路与解答 三、错误票据 3、1 题目描述 3、2 题解关键思路与解答 四、回文日期 4、1 题目描述 4、2 题解关键思路与解答 五、归并排序 标题:蓝桥杯—