PAT (Advanced Level) Practice 1003 Emergency
思路:用深搜遍历出所有可达路径,每找到一条新路径时,对最大救援人数和最短路径数进行更新。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=;
int tu[N][N],city[N],vis[N];//tu存道路,city存各城市救援人数,vis为标记数组
int n,m,start,dis,path=,shortest=1e8,allpeople=;//path为最短路径数,allpeople为最大救援人数
void read()
{
memset(vis,,sizeof(vis));
fill(tu[],tu[]+N*N,);
cin>>n>>m>>start>>dis;
for (int i=;i<n;i++)
cin>>city[i];
int a,b,c;
for (int i=;i<m;i++)
{
cin>>a>>b>>c;
tu[a][b]+=c;//注意题目,是无向图!!
tu[b][a]+=c;
}
}
void dfs(int step,int now,int people)
{
people+=city[now];//要先加上该城市救援人数!
if (now==dis)
{
if (step<shortest)
{
shortest=step;
allpeople=people;
path=;
}
else if (step==shortest)//这里要用else if不能用if!!如果用if会在第一次更新时满足这两个if判断,导致path多加了一次!!
{
path++;
allpeople=max(allpeople,people);
}
return;
}
vis[now]=;
for (int i=;i<n;i++)
{
if (tu[now][i]>&&vis[i]==)
{
step+=tu[now][i];
dfs(step,i,people);
step-=tu[now][i];
}
}
vis[now]=;
}
int main()
{
// freopen("in.txt","r",stdin);
read();//输入函数
dfs(,start,);//深搜遍历所有路径
cout<<path<<" "<<allpeople<<endl; return ;
}
PAT (Advanced Level) Practice 1003 Emergency的更多相关文章
- PAT (Advanced Level) Practice 1003 Emergency 分数 25 迪杰斯特拉算法(dijkstra)
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- PAT (Advanced Level) Practise 1003 Emergency(SPFA+DFS)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT (Advanced Level) Practice 1001-1005
PAT (Advanced Level) Practice 1001-1005 PAT 计算机程序设计能力考试 甲级 练习题 题库:PTA拼题A官网 背景 这是浙大背景的一个计算机考试 刷刷题练练手 ...
- PAT (Advanced Level) Practice(更新中)
Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...
- PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...
- PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...
- PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642
PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...
- PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642
PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...
- PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642
PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642 题目描述: Given any string of N (≥5) ...
随机推荐
- Django路由系统---django重点之url映射分发
django重点之url映射分发 在全局项目的urls.py中进行子项目的映射,然后在子项目中创建一个urls.py去处理自己项目中的请求,同时也实现了代码的解耦 添加路由分发的原则[全局urls.p ...
- centos7 docker 使用pipework 做虚拟机
网卡配置文件 及 bridge的静态配置 centos7 Bridge配置 [root@mon-1 ~]# cd /etc/sysconfig/network-scripts/ [root@mon- ...
- 软件cs页面分辨率测试
1.为什么软件要进行分辨率兼容性测试 用户的环境可能大多数是主流的分辨率,如1024x768,1366x700,但是我们还是遇到了一些使用上网本的用户,他的上网本分辨率是1024x600,由于我们的软 ...
- How to Remove A Service Entry From Win10 Service List
Warning Please do this operation CAREFULLY, otherwise you may get something wrong with your system. ...
- echo 与 od -x 与 %!xxd 命令
echo 与 od -x 与 %!xxd 命令 echo 命令 -n 选项 可以使其不带换行符od -x 命令可以查看文件的16进制表示%!xxd 可以在vim编辑器中dump成16进制表示
- 创建工程支持scala代码开发
第一步:idea当中创建创建普通maven工程 File ==> New ==> Project 第二步:修改pom.xml添加scala的版本以及打包插件 <dependencie ...
- Nginx and PHP-FPM Configuration and Optimizing Tips and Tricks
原文链接:http://www.if-not-true-then-false.com/2011/nginx-and-php-fpm-configuration-and-optimizing-tips- ...
- 理解活在Iphone中的那些App (一)
关于一个app的生命 干IOS开发两年多了,如果把大学中的时间也算上,编程也有六年了.这些时间中,从一个懵懵懂懂的学徒,变成一个还算熟练的码农,也多多少少有一点反思.于是,边促成了理解活在Iphone ...
- js字符串和数组
sustr substring slice的联系与区别 str.substr(2,5) //从索引2开始截取5个字符,原有字符串str不变 str.substring(2,5) //从索引2开始截 ...
- BZOJ 1015 星球大战starwar 逆向并查集
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1015 题目大意: 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个 ...