Checkpoints(第十一届河南省省赛真题)
题目描述
As a landlocked country in central and southern Africa , the political situation has been relatively stable since the implementation of multi-party elections in ZBA in 1991. But the ZBA parliament passed the 90 day emergency order issued by the president on 11 days of local time . The tension is that the patriotic team led by the government troops and NPG leaders founded by aborigines started, in addition to the unlawful insurgents of illegal militants.
Chinese peacekeepers are going to the town of Kerver to seek Chinese foreign aid engineers.
The military map shows that there are many checkpoints in the war zone. It can be modeled as a directed graph: nodes represent checkpoints , and edges represents the roads. The goal is that the less peacekeepers pass the checkpoints, the safer it will be.
输入
Input
The first line of the input contains one integer T, which is the number of test cases (1<=T<=5). Each test case specifies:
* Line 1: N M A B (2 ≤ N ≤ 100)
N and M denote the number of nodes and edges in the directed graph respectively. The checkpoints are labeled 1, 2, ..., N, where chinese peacekeepers at node A and foreign aid engineers at node B.
*Line 2~m+1: Xi Yi (i=1, …., M)
followed by M lines containing two integers Xi and Yi (1 ≤ Xi, Yi ≤ N), denoting that there is a directed edge from node Xi to node Yi in the network.
输出
Output
For each test case generate a single line: a single integer that the minimum number of checkpoints . If a checkpoint is passed on the way back and forth , it will be counted only once.
样例输入
- 1
- 6 10 1 5
- 1 2
- 2 1
- 2 3
- 3 5
- 5 4
- 4 2
- 1 6
- 6 5
- 5 3
- 3 2
样例输出
- 2
- /*
- 问题
- 输入节点数和边数,起点和终点,以及每一条边,计算从起点到终点再返回起点途中最少要经过几个顶点,重复的点不计。
- 解题思路
- 采用Dijkstra算法求一下起点到个点的最短路,然后将走过的点标记一下,再求一下终点到其他点的最短距离,标记过的点
- 不计算就可以了。
- */
- #include<cstdio>
- #include<cstring>
- int e[][],book[],n,m,ans;
- void Dijkstra(int s);
- int main()
- {
- int T,u,v,a,b,i,j;
- scanf("%d",&T);
- while(T--){
- scanf("%d%d%d%d",&n,&m,&a,&b);
- for(i=;i<n;i++){
- for(j=;j<n;j++){
- e[i][j] = i==j?:;
- }
- }
- memset(book,,sizeof(book));
- while(m--){
- scanf("%d%d",&u,&v);
- e[u][v]=;
- }
- ans=;
- Dijkstra(a);
- Dijkstra(b);
- printf("%d\n",ans);
- }
- return ;
- }
- void Dijkstra(int s)
- {
- int dis[],bk[]={},i,j;
- for(i=;i<n;i++)
- dis[i]=e[s][i];
- dis[s]=;
- int u=;
- bk[s]=;
- for(i=;i<n;i++){
- int mina=;
- for(j=;j<n;j++){
- if(bk[j] == && dis[j] < mina){
- dis[j]=mina;
- u=j;
- }
- }
- bk[u]=;
- if(book[u] == )
- ans++;
- book[u]=;
- for(j=;j<n;j++){
- if(bk[j] == && dis[j] < e[u][j]){
- dis[j]=e[u][j];
- }
- }
- }
- }
Checkpoints(第十一届河南省省赛真题)的更多相关文章
- 求XF+闭包(第十一届河南省省赛真题)
题目描述 如何设计一个好的数据库不仅仅是一个理论研究问题,也是一个实际应用问题.在关系数据库中不满足规范化理论的数据库设计会存在冗余.插入异常.删除异常等现象. 设R(U)是一个关系模式,U={ A1 ...
- ACM 第十一届 河南省省赛A题 计划日
一.题目描述如下: 二.思路分析 其实这个如果是一个填空题,可以直接用Excel快速计算出来,反而用代码比较麻烦 说一下我的代码的思路: 1.如果N大于本月剩下的天数,就先从N天里减去本月剩下的天数, ...
- 2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告
2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh ...
- 第十届蓝桥杯JavaB组省赛真题
试题 A: 组队 本题总分:5 分 [问题描述] 作为篮球队教练,你需要从以下名单中选出 1 号位至 5 号位各一名球员, 组成球队的首发阵容. 每位球员担任 1 号位至 5 号位时的评分如下表所示. ...
- Python解答蓝桥杯省赛真题之从入门到真题(二刷题目一直更新)
蓝桥刷题 原文链接: https://github.com/libo-sober/LanQiaoCup Python解答蓝桥杯省赛真题之从入门到真题 不同字串 """ 一 ...
- 第九届蓝桥杯JavaC组决(国)赛真题
1:年龄问题 s夫人一向很神秘.这会儿有人问起她的年龄,她想了想说: "20年前,我丈夫的年龄刚好是我的2倍,而现在他的年龄刚好是我的1.5倍". 你能算出s夫人现在的年龄吗? 这 ...
- Java实现第十一届蓝桥杯JavaB组 省赛真题
试题 A: 指数计算 本题总分:5 分 [问题描述] 7 月 1 日是建党日,从 1921 年到 2020 年, 已经带领中国人民 走过了 99 年. 请计算:7 ^ 2020 mod 1921,其中 ...
- 第十届蓝桥杯JavaC组省赛真题
试题 A: 求和 本题总分:5 分 [问题描述] 小明对数位中含有 2.0.1.9 的数字很感兴趣,在 1 到 40 中这样的数包 括 1.2.9.10 至 32.39 和 40,共 28 个,他们的 ...
- 第九届蓝桥杯JavaA组省赛真题
解题代码部分来自网友,如果有不对的地方,欢迎各位大佬评论 题目1.分数 题目描述 1/1 + 1/2 + 1/4 + 1/8 + 1/16 + - 每项是前一项的一半,如果一共有20项, 求这个和是多 ...
随机推荐
- Anroid 手机助手 详细解析 概述(二)
这篇主要说一下手机插入之后的一些动作. 1) 捕获窗口消息 插入拔出一个USB设备windows 会给所有的窗口发送特定的消息,只要我们捕获这些消息就可以处理设备插入和拔出.需要注意的是插入或者拔出 ...
- cxGrid实现取消过滤和排序后定位到首行(单选和多选)
cxGrid实现取消过滤和排序后定位到首行(单选和多选) 原创 2013年10月06日 18:42:24 2107 DataContoller中的函数FocusedRecordIndex没有反应,Fo ...
- iOS 百度地图截屏
关于百度地图截屏的问题,发现不能用常用的方法进行载屏,常用的截屏方法所得到的图片地图瓦片底图会显示空白,网上给出的答案是这样的 :因为百度地图不是用UIKit实现的,所以得不到截图! 不过通过Open ...
- Apache中 RewriteCond 规则参数介绍
RewriteCond指令定义了规则生效的条件,即在一个RewriteRule指令之前可以有一个或多个RewriteCond指令.条件之后的重写规则仅在当前URI与Pattern匹配并且满足此处的条件 ...
- 撸.NET Core的正确姿势
特点 案例基于刚发布的.NET Core 2.1 只需一台Linux服务器搞定一切, 全程无需自己配置dotnet环境, 需要熟悉git docker基础知识可有可无, 过了下面几个步骤,你就已经入门 ...
- log4j的日志级别(ssm中log4j的配置)
log4j定义了8个级别的log(除去OFF和ALL,可以说分为6个级别),优先级从高到低依次为:OFF.FATAL.ERROR.WARN.INFO.DEBUG.TRACE. ALL. 1. ALL ...
- python爬虫在解析不带引号的json报错的问题解决方案
本例中环境: python3.6.6 demjson-2.2.4 如不看废话请直接看3(下面红体字) 1.近期在爬取代理验证代理的时候发生一个Bug, 就是在验证代理的时候返回的是如下字符串, {ip ...
- 关于AOP的PIAB
AOP:面向切面编程,也就是在运行过程中,按照需要动态加载功能块 PIAB:含义可以从下面提取 Microsoft Patterns & Practices团队在2007年发布的Enterpr ...
- swiper4-vue 不使用loop,由最后一张跳到第一张
<template> <div class="swiper-box"> <div class="swiper-container" ...
- Numpy.random中shuffle与permutation的区别(转)
huffle与permutation的区别 函数shuffle与permutation都是对原来的数组进行重新洗牌(即随机打乱原来的元素顺序):区别在于shuffle直接在原来的数组上进行操作,改变原 ...