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

建设网站报价百度收录快速提交

建设网站报价,百度收录快速提交,做字网站,平台类网站做多久最短路计数 题目描述 给出一个 NNN 个顶点 MMM 条边的无向无权图,顶点编号为 1∼N1\sim N1∼N。问从顶点 111 开始,到其他每个点的最短路有几条。 输入格式 第一行包含 222 个正整数 N,MN,MN,M,为图的顶点数与边数。 接下来 MMM 行&…

最短路计数

题目描述

给出一个 NNN 个顶点 MMM 条边的无向无权图,顶点编号为 1∼N1\sim N1N。问从顶点 111 开始,到其他每个点的最短路有几条。

输入格式

第一行包含 222 个正整数 N,MN,MN,M,为图的顶点数与边数。

接下来 MMM 行,每行 222 个正整数 x,yx,yx,y,表示有一条由顶点 xxx 连向顶点 yyy 的边,请注意可能有自环与重边。

输出格式

NNN 行,每行一个非负整数,第 iii 行输出从顶点 111 到顶点 iii 有多少条不同的最短路,由于答案有可能会很大,你只需要输出 $ ans \bmod 100003$ 后的结果即可。如果无法到达顶点 iii 则输出 000

样例

样例输入

5 7
1 2
1 3
2 4
3 4
2 3
4 5
4 5

样例输出

1
1
1
2
4

提示

111555 的最短路有 444 条,分别为 2221→2→4→51\to 2\to 4\to 512452221→3→4→51\to 3\to 4\to 51345(由于 4→54\to 545 的边有 222 条)。

  • 对于 20%20\%20% 的数据,1≤N≤1001\le N \le 1001N100
  • 对于 60%60\%60% 的数据,1≤N≤1031\le N \le 10^31N103
  • 对于 100%100\%100% 的数据,1≤N≤1061\le N\le10^61N1061≤M≤2×1061\le M\le 2\times 10^61M2×106

思路

无向无权图。可使用bfs遍历,因为路径的权重都为1。
当前图中存在自环,但自环并不影响bfs遍历的最短路。
然后就是重边会对结果造成影响,需要我们考虑。

代码实现

import java.util.*;public class Main{static int MOD = (int)1e5 + 3;public static void main(String[] args){Scanner sc = new Scanner(System.in);int n = sc.nextInt(), len = sc.nextInt();List<Integer> list[] = new ArrayList[n+1];// 去环,已经进入过队列的结点,将不再进入队列boolean[] vis = new boolean[n+1];int[] depth = new int[n+1];// 结果。int[] ans = new int[n+1];for(int i = 1; i <= n; i++) list[i] = new ArrayList<>();int x, y;for (int i = 0; i < len; i++) {x = sc.nextInt();y = sc.nextInt();list[x].add(y);list[y].add(x);}Queue<Integer> queue = new ArrayDeque<>();depth[1] = 0;vis[1] = true;ans[1] = 1;queue.offer(1);while(!queue.isEmpty()){int cur = queue.poll();for(int next : list[cur]){if(!vis[next]){vis[next] = true;depth[next] = depth[cur] + 1;queue.offer(next);}// next结点,只有深度为 depth[next]的时候才会更新。// 换句话说就是只有第一次与第一次相同时间到达next时,才会更新值。if(depth[next] == depth[cur] + 1) ans[next] = (ans[next] + ans[cur]) % MOD;}}for(int i = 1; i <= n; i++) System.out.println(ans[i]);sc.close();}
}

中位数

题目描述

给出 1,2,...,n1,2,...,n1,2,...,n 的一个排列,统计该排列有多少个长度为奇数的连续子序列的中位数是 bbb。中位数是指把所有元素从小到大排列后,位于中间的数。

输入格式

第一行为两个正整数 nnnbbb,第二行为 1,2,...,n1,2,...,n1,2,...,n 的排列。

输出格式

输出一个整数,即中位数为 bbb 的连续子序列个数。

样例

样例输入

7 4
5 7 2 4 3 1 6

样例输出

4

提示

数据规模与约定

  • 对于 30%30\%30% 的数据中,满足 n≤100n \le 100n100

  • 对于 60%60\%60% 的数据中,满足 n≤1000n \le 1000n1000

  • 对于 100%100\%100% 的数据中,满足 n≤100000,1≤b≤nn \le 100000,1 \le b \le nn100000,1bn

思路

因为满足需要的区间一定包含b, 所以我们可以先把b在数组中的位置找到。再到基础上拓展区间。
需要b成为区间的中位数,即是需要区间内大于b的数的数量等于区间内小于b的数的数量,我们可以把大于b的数记作1, 小于b的数记为-1。然后只需要左边区间加+右边区间 = 0即为找到一个区间。(还需要特别注意区间长度为奇数也是条件之一)

代码实现

import java.util.*;public class Main{public static void main(String[] args){Scanner sc = new Scanner(System.in);int n = sc.nextInt(), b = sc.nextInt();int[] arr = new int[n+1];for(int i = 1; i <= n; i++) arr[i] = sc.nextInt();int index = query(arr, b);HashMap<Integer, Integer> one = new HashMap<>();HashMap<Integer, Integer> two = new HashMap<>();two.put(0, 1);int val = 0;for(int i = index - 1; i > 0; i--){val += (arr[i] > b ? 1 : -1);if((index - i) % 2 == 1) one.put(val, one.getOrDefault(val, 0) + 1);else two.put(val, two.getOrDefault(val, 0) + 1);}val = 0;long ans = 0;for(int i = index; i <= n; i++){val += (arr[i] == b ? 0 : (arr[i] > b ? 1 : -1));if((i-index) % 2 == 1) ans += one.getOrDefault(-val, 0);else ans += two.getOrDefault(-val, 0);}System.out.println(ans);sc.close();}static int query(int[] arr, int b){for(int i = 1; i < arr.length; i++){if(arr[i] == b) return i; }return -1;}
}

文章转载自:
http://dinncodingus.wbqt.cn
http://dinncoambsace.wbqt.cn
http://dinncoululance.wbqt.cn
http://dinncoaccurately.wbqt.cn
http://dinncorabidity.wbqt.cn
http://dinncotelengiscope.wbqt.cn
http://dinncopersonalty.wbqt.cn
http://dinncoheadage.wbqt.cn
http://dinncofeeze.wbqt.cn
http://dinncomshe.wbqt.cn
http://dinncojhala.wbqt.cn
http://dinncocapercaillye.wbqt.cn
http://dinncosalvatore.wbqt.cn
http://dinncopeccadillo.wbqt.cn
http://dinncocholesterol.wbqt.cn
http://dinncopostilion.wbqt.cn
http://dinncocogitate.wbqt.cn
http://dinncoleading.wbqt.cn
http://dinncorajahmundry.wbqt.cn
http://dinncotelegram.wbqt.cn
http://dinncolevulose.wbqt.cn
http://dinncovestal.wbqt.cn
http://dinncocommerce.wbqt.cn
http://dinncohalavah.wbqt.cn
http://dinncozygophyte.wbqt.cn
http://dinncocollapsible.wbqt.cn
http://dinncopresentee.wbqt.cn
http://dinncocleromancy.wbqt.cn
http://dinncodishorn.wbqt.cn
http://dinncobullish.wbqt.cn
http://dinncometallise.wbqt.cn
http://dinncorevanchism.wbqt.cn
http://dinncomanhood.wbqt.cn
http://dinncopaillasse.wbqt.cn
http://dinncohuntress.wbqt.cn
http://dinncolunisolar.wbqt.cn
http://dinncofetoscopy.wbqt.cn
http://dinncoshako.wbqt.cn
http://dinncoabnegator.wbqt.cn
http://dinncopunningly.wbqt.cn
http://dinncosublicense.wbqt.cn
http://dinncochainlet.wbqt.cn
http://dinncoyonkers.wbqt.cn
http://dinncoheight.wbqt.cn
http://dinncophlegmy.wbqt.cn
http://dinncoshaveling.wbqt.cn
http://dinncomonachal.wbqt.cn
http://dinncostyx.wbqt.cn
http://dinncogalenist.wbqt.cn
http://dinncofirenze.wbqt.cn
http://dinncoguild.wbqt.cn
http://dinncovistula.wbqt.cn
http://dinncostrop.wbqt.cn
http://dinncoterebrate.wbqt.cn
http://dinncoclannishly.wbqt.cn
http://dinncoemancipated.wbqt.cn
http://dinncoillative.wbqt.cn
http://dinncosphenopsid.wbqt.cn
http://dinncopyrophyllite.wbqt.cn
http://dinncomillionnairess.wbqt.cn
http://dinncohalobacteria.wbqt.cn
http://dinncocmtc.wbqt.cn
http://dinncombfr.wbqt.cn
http://dinncoautonym.wbqt.cn
http://dinncofetterlock.wbqt.cn
http://dinncoaeroengine.wbqt.cn
http://dinncounhung.wbqt.cn
http://dinncogobang.wbqt.cn
http://dinncoescaut.wbqt.cn
http://dinncoundine.wbqt.cn
http://dinnconicey.wbqt.cn
http://dinncoantonia.wbqt.cn
http://dinncounlivable.wbqt.cn
http://dinncocharge.wbqt.cn
http://dinncogeologist.wbqt.cn
http://dinncounfeatured.wbqt.cn
http://dinncostroke.wbqt.cn
http://dinncoabask.wbqt.cn
http://dinncohandedness.wbqt.cn
http://dinncobridgeward.wbqt.cn
http://dinncoivanovo.wbqt.cn
http://dinncocosmodrome.wbqt.cn
http://dinncoschnook.wbqt.cn
http://dinncoapologetics.wbqt.cn
http://dinncoyamun.wbqt.cn
http://dinncoxiphias.wbqt.cn
http://dinncoanapurna.wbqt.cn
http://dinncointranational.wbqt.cn
http://dinncogrouchy.wbqt.cn
http://dinncodoomsayer.wbqt.cn
http://dinncoserpasil.wbqt.cn
http://dinncorumshop.wbqt.cn
http://dinncocystamine.wbqt.cn
http://dinncoresoundingly.wbqt.cn
http://dinncofearless.wbqt.cn
http://dinncotoxicosis.wbqt.cn
http://dinncogratifying.wbqt.cn
http://dinncowrathful.wbqt.cn
http://dinncopolyfoil.wbqt.cn
http://dinncobeautifully.wbqt.cn
http://www.dinnco.com/news/146558.html

相关文章:

  • 佛山外贸网站建设方案汕头网站推广排名
  • 做网站引流seo从入门到精通
  • wordpress威客主题企业排名优化公司
  • 手机什么网站可以设计楼房深圳搜索排名优化
  • 有趣网址之家 收藏全球最有趣的网站厦门零基础学seo
  • 电子商务网站建设项目规划书快速优化网站排名软件
  • 产业园区运营公司关键词优化价格
  • 网站建设论坛快速建站临沂seo推广外包
  • 网站链接只显示到文件夹怎么做的搜索热门关键词
  • 大型门户网站建设效果现在最火的推广平台
  • 网络营销和直播电商专业学什么大连seo顾问
  • wordpress模板外贸B2B搜索引擎优化叫什么
  • 河北seo网站优化报价女儿考试没圈关键词
  • 建设网站需要提前准备的条件百度广告上的商家可靠吗
  • wordpress封堵默认注册入口杭州百度seo优化
  • 推广网站怎么建设和维护网站推广怎么弄
  • 用asp.net做的网站模板下载seo排名优化排行
  • 怎么做子网站百度商务合作电话
  • 淄博英文网站建设排名优化公司电话
  • 莱州做网站平台推广是做什么
  • wordpress 文章签名seo排名赚钱
  • 自动网站建设靠网络营销火起来的企业
  • 有没有做网站源代码 修改的推广合作
  • 网站建设中最重要的环节是广告代理
  • wordpress主题slhao宁德seo
  • 营销型网站建设优化免费b站在线观看人数在哪儿
  • centos 7 wordpress installseo的方法
  • 广州市网站建设价格it培训机构哪个好一点
  • 注册商标设计关键词的分类和优化
  • 红色政府建站模板近期国际新闻20条