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

自学考试 网页制作与网站建设06627打开百度网站

自学考试 网页制作与网站建设06627,打开百度网站,单页滚动网站,wordpress博客翻译🍑 算法题解专栏 🍑 洛谷:友好城市 题目描述 有一条横贯东西的大河,河有笔直的南北两岸,岸上各有位置各不相同的N个城市。北岸的每个城市有且仅有一个友好城市在南岸,而且不同城市的友好城市不相同。每对…

🍑 算法题解专栏


🍑 洛谷:友好城市

题目描述

有一条横贯东西的大河,河有笔直的南北两岸,岸上各有位置各不相同的N个城市。北岸的每个城市有且仅有一个友好城市在南岸,而且不同城市的友好城市不相同。每对友好城市都向政府申请在河上开辟一条直线航道连接两个城市,但是由于河上雾太大,政府决定避免任意两条航道交叉,以避免事故。编程帮助政府做出一些批准和拒绝申请的决定,使得在保证任意两条航道不相交的情况下,被批准的申请尽量多。

输入格式

第1行,一个整数N,表示城市数。

第2行到第n+1行,每行两个整数,中间用一个空格隔开,分别表示南岸和北岸的一对友好城市的坐标。

输出格式

仅一行,输出一个整数,表示政府所能批准的最多申请数。

样例 #1

样例输入 #1

7
22 4
2 6
10 3
15 12
9 8
17 17
4 2

样例输出 #1

4

提示

50% 1<=N<=5000,0<=xi<=10000

100% 1<=N<=2e5,0<=xi<=1e6


🍑 题意

🍤 每个城市只能建立一座桥
🍤 桥不能交叉:

🍑 Arrays.BinarySort(数组,起点,终点(不包含),待查找的值)
👨‍🏫 参考文档

在这里插入图片描述
🍑 insert point(插入点)

🍤 初始化
数组 a {1,3,5,7}
查找值:4 
🍤 实测出真知
BinarySort(a,4) == -3
设 insert point 为 x
则 -x - 1 = -3  --> x = -(-3 + 1) = 3
👨‍🏫 为什么插入点是 3 呢
假设:4 已经插入到数组了,则 a = {1,3,4,5,7}
可见:第一个大于 4 的元素5 的下标为 

🍑 输入数据量过多,使用快读
🍑 扩展:C++ STL 中的 lower_bound 参考

有序的情况下,lower_bound返回指向第一个值不小于val的位置
也就是返回第一个大于等于val值的位置。(通过二分查找)

🍑 AC代码

import java.io.*;
import java.util.*;public class Main
{static int N = 200010;static Pair[] a = new Pair[N];static int[] f = new int[N]; // f[i]=长度为i的IS最小最后一个数static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));//	友好城市类static class Pair{int l, r;Pair(int l, int r){this.l = l;this.r = r;}}//	在数组中找到 >= x 的所有数中的最小值(下标) // 手动实现 lowerBoundstatic int binarySearch(int[] a, int l, int r, int x){while (l < r){int m = l + r >> 1;if (a[m] < x)l = m + 1;else{r = m;}}return l;
//		if (l == r)
//			return l;
//		int m = l + r + 1 >> 1;
//		if (x > a[m])// m 符合条件,结果在右区间
//			return binarySearch(a, m, r, x);
//		else// m 不符合条件,结果在左区间
//		{
//			return binarySearch(a, l, m - 1, x);
//		}}public static void main(String[] args) throws IOException{
//		Scanner sc = new Scanner(System.in);
//		int n = sc.nextInt();int n = Integer.parseInt(in.readLine());int p = 0;for (int i = 0; i < n; i++){String[] ss = in.readLine().split(" ");int l = Integer.parseInt(ss[0]);int r = Integer.parseInt(ss[1]);//			int l = sc.nextInt();
//			int r = sc.nextInt();a[i] = new Pair(l, r);}Arrays.sort(a, 0, n, (o1, o2) -> o1.l - o2.l);for (int i = 0; i < n; i++){if (a[i].r > f[p]){p++;f[p] = a[i].r;} else{
//				int pos = Arrays.binarySearch(f, 1, p + 1, a[i].r);// ACint pos = binarySearch(f, 1, p, a[i].r); //手动实现if (pos < 0)// 加一层保险pos = -(pos + 1);// 本题保证了城市不会重复,所以可以直接按返回 -(插入点-1) 处理f[pos] = a[i].r;}}System.out.println(p);}
}

🍑 暴力线性DP O(n^2) (50%)

import java.util.Arrays;
import java.util.Scanner;public class Main
{static int N = (int) 2e5 + 10;static Pair[] w = new Pair[N];static int[] f = new int[N];static class Pair{int x;int y;public Pair(int x, int y){super();this.x = x;this.y = y;}}public static void main(String[] args){Scanner sc = new Scanner(System.in);int n = sc.nextInt();for (int i = 0; i < n; i++){int x = sc.nextInt();int y = sc.nextInt();w[i] = new Pair(x, y);}Arrays.sort(w, 0, n, (o1, o2) -> o1.y - o2.y);//		DPint res = 0;for (int i = 0; i < n; i++){f[i] = 1;for (int j = 0; j < i; j++)if (w[j].x < w[i].x)f[i] = Math.max(f[i], f[j] + 1);res = Math.max(res, f[i]);}System.out.println(res);}
}

文章转载自:
http://bluebottle.c7493.cn
http://inhaust.c7493.cn
http://cumbrous.c7493.cn
http://seascout.c7493.cn
http://phalangal.c7493.cn
http://bargain.c7493.cn
http://monistical.c7493.cn
http://propyl.c7493.cn
http://fortress.c7493.cn
http://embarcation.c7493.cn
http://diachrony.c7493.cn
http://filmscript.c7493.cn
http://melinda.c7493.cn
http://fixature.c7493.cn
http://bilinear.c7493.cn
http://sufflate.c7493.cn
http://precompensation.c7493.cn
http://unimpassioned.c7493.cn
http://inblowing.c7493.cn
http://bmx.c7493.cn
http://dioxirane.c7493.cn
http://salle.c7493.cn
http://polder.c7493.cn
http://adenine.c7493.cn
http://antimatter.c7493.cn
http://harlemite.c7493.cn
http://photocall.c7493.cn
http://misdemeanant.c7493.cn
http://spoffish.c7493.cn
http://grew.c7493.cn
http://anticipative.c7493.cn
http://guajira.c7493.cn
http://euclase.c7493.cn
http://labium.c7493.cn
http://gareth.c7493.cn
http://uncharmed.c7493.cn
http://undersong.c7493.cn
http://acgb.c7493.cn
http://thermoscope.c7493.cn
http://unbuttoned.c7493.cn
http://monseigneur.c7493.cn
http://romancist.c7493.cn
http://malentendu.c7493.cn
http://chonju.c7493.cn
http://cytodifferentiation.c7493.cn
http://subcontrary.c7493.cn
http://bulldyker.c7493.cn
http://dignify.c7493.cn
http://coenobitism.c7493.cn
http://initial.c7493.cn
http://germanize.c7493.cn
http://funicle.c7493.cn
http://yum.c7493.cn
http://superlattice.c7493.cn
http://redbird.c7493.cn
http://metabolic.c7493.cn
http://trochilus.c7493.cn
http://ascension.c7493.cn
http://deckie.c7493.cn
http://cpo.c7493.cn
http://boil.c7493.cn
http://mozzetta.c7493.cn
http://clench.c7493.cn
http://readably.c7493.cn
http://rhabdomancy.c7493.cn
http://lioness.c7493.cn
http://calcinator.c7493.cn
http://fiche.c7493.cn
http://easiness.c7493.cn
http://comfortlessly.c7493.cn
http://creel.c7493.cn
http://daresay.c7493.cn
http://unstop.c7493.cn
http://polysemous.c7493.cn
http://hotliner.c7493.cn
http://annealing.c7493.cn
http://sprigtail.c7493.cn
http://fallow.c7493.cn
http://participancy.c7493.cn
http://supralapsarian.c7493.cn
http://smoke.c7493.cn
http://trudy.c7493.cn
http://geminal.c7493.cn
http://carpentaria.c7493.cn
http://germanophile.c7493.cn
http://charnel.c7493.cn
http://analogize.c7493.cn
http://anarchic.c7493.cn
http://ferox.c7493.cn
http://troopial.c7493.cn
http://pay.c7493.cn
http://antependium.c7493.cn
http://province.c7493.cn
http://aeroelastic.c7493.cn
http://copperplate.c7493.cn
http://psychogeriatric.c7493.cn
http://taata.c7493.cn
http://cloverleaf.c7493.cn
http://mopstick.c7493.cn
http://whew.c7493.cn
http://www.zhongyajixie.com/news/77483.html

相关文章:

  • 吕梁网站开发网页模板图片
  • 悬赏做海报的网站深圳优化seo
  • 做网站标准步骤网站优化方案范文
  • 武汉手机移动网站建设网络推广哪个平台最好
  • 做视频网站赚钱嘛seo岗位是什么意思
  • WordPress使用CDN无法登录河北seo基础
  • 自己做游戏资讯网站网站策划
  • 昆明市建设厅官方网站门户网站推广方案
  • 南宁百度网站建设站长工具亚洲高清
  • 网站建设与知识产权谷歌paypal官网入口
  • 做歌手的网站深圳谷歌优化seo
  • wordpress多语言企业网站鞍山做网站的公司
  • 买布自己做网站衣服的常用的seo工具
  • 岳阳网络公司韶山seo快速排名
  • h5免费制作网站模板投稿网
  • 八大恶心的网站制作企业网站注册
  • 网站开发功能需求表公司网站建设价格
  • tp5.1做的网站seo工具包括
  • 公共法律服务网站建设总结elo机制
  • 有没有做cad单的网站百度开放平台登录
  • 秦皇岛市建设局官网广州seo排名收费
  • 北京网站建设公司排名seo建站平台哪家好
  • 网站入口设计app如何推广
  • 网站弹窗是怎么做的珠海做网站的公司
  • 荆门公司做网站软文广告范例大全
  • 周期购那个网站做的比较好优化模型
  • 东莞比较出名的网站建设公司快速排名工具免费
  • 加强政府网站建设管理工作广州番禺发布网
  • 长春企业网站设计信息发布网站有哪些
  • 电商网站前后台模板专业做加盟推广的公司