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项, 求这个和是多 ...
随机推荐
- sql一些基本的语法
1.if语句: 语法:IF(expr1,expr2,expr3) 其中,expr1是判断条件,expr2和expr3是符合expr1的自定义的返回结果. 用处:当从数据库中查询出来的结果需要转换成中文 ...
- Android GridView 滑动条设置一直显示状态
模拟GridView控件: <GridView android:id="@+id/picture_grid" android:layout_width="match ...
- 个人作业四--Alpha阶段个人总结
一.个人总结 在alpha 结束之后, 每位同学写一篇个人博客, 总结自己的alpha 过程: 请用自我评价表:http://www.cnblogs.com/xinz/p/3852177.html 有 ...
- 浅析C#中的Thread ThreadPool Task和async/await
.net 项目中不可避免地要与线程打交道,目的都是实现异步.并发.从最开始的new Thread()入门,到后来的Task.Run(),如今在使用async/await的时候却有很多疑问. 先来看一段 ...
- 【有新题】OCP 12c 062出现大量新考题-14
choose two You plan to upgrade your Oracle Database 9i to Oracle Database 12c. Which two methods can ...
- [vue] [axios] 设置代理实现跨域时的纠错
# 第一次做前端工程 # 记一个今天犯傻调查的问题 -------------------------------------------------------------------------- ...
- DNS 预解析
DNS 解析也是需要时间的,可以通过预解析的方式来预先获得域名所对应的 IP. <link rel="dns-prefetch" href="//yuchengka ...
- postgresql-脏页和缓存失效
脏页和缓存失效 https://www.cnblogs.com/flying-tiger/p/7885478.html Dirty pages and cache invalidation 我们一直在 ...
- centos7搭建mysql5.7主从同步
主从基本概念 mysql主从同步定义 主从同步使得数据可以从一个数据库服务器复制到其他服务器上,在复制数据时,一个服务器充当主服务器(master),其余的服务器充当从服务器(slave).因为复制是 ...
- 【tomcat】servlet原理及其生命周期
1.什么是servlet? Servlet(Servlet Applet),全称Java Servlet,是用Java编写的服务器端程序.而这些Servlet都要实现Servlet这个接口.其主要功能 ...