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) ...
随机推荐
- plsql连接12cR2 PDB报错ORA-28040/ORA-01017
http://hbxztc.blog.51cto.com/1587495/1907533 PS: 在数据库服务器上的oracle/network/admin/sqlnet.ora文件添加一行SQLNE ...
- Intellij IDEA常用快捷键和一些配置——Mac版
常用的快捷键 代码补全Ctrl + space 删除行Command + D 注释Command + / 导入包Command + shift + O 格式化代码Command + shift + F ...
- DOM节点中获取文本易混淆的属性
DOM 节点中对于获取文本易混淆的属性,innerText, innerHTML, outerHTML, textContent, nodeValue. 一个实例: <!DOCTYPE html ...
- OS开发小记:iOS富文本框架DTCoreText在UITableView上的使用
要在页面中显示自己的布局,比如文字的字体和颜色.图文并排的样式,我们要用iOS SDK的原生UI在app本地搭建,如果一个页面需要在服务器端获取数据的话,我们也要在本地搭建好固定的布局,解析服务器传回 ...
- swift 第一个IOS应用程序
swift 出来也有一阵子了,一直没有时间来研究.简单的看了看.随手写几篇文章.特此声明:本博客纯属个人学习,有不足之处,属于正常,希望多多见谅. 第一个IOS应用程序开发 一.准备工作: (1)Ma ...
- gluoncv rpn 正负样本
https://github.com/dmlc/gluon-cv/blob/master/gluoncv/model_zoo/rpn/rpn_target.py def forward(self, i ...
- Hadoop学习之路(二十七)MapReduce的API使用(四)
第一题 下面是三种商品的销售数据 要求:根据以上数据,用 MapReduce 统计出如下数据: 1.每种商品的销售总金额,并降序排序 2.每种商品销售额最多的三周 第二题:MapReduce 题 现有 ...
- PAT——1029. 旧键盘
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及实际被输入的文字,请你列出肯定坏掉的那些键. 输入格式: 输入在2行中分别给出应该输入的文字.以及实际 ...
- lwip BUG ,导致 系统 死机
pcb->snd_queuelen >= pbuf_clen(next->p) sys_arch_assert: in ..\..\User\lwip\src\core\tcp_in ...
- nRF5 SDK for Mesh(六) BLE MESH 的 基础概念
Basic Bluetooth Mesh concepts The Bluetooth Mesh is a profile specification developed and published ...