PAT:1003. Emergency (25)
来源:互联网 发布:身份证阅读器软件下载 编辑:程序博客网 时间:2024/06/06 00:57
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.io.*;
import java.util.Iterator;
class Emergency
{
int []dist;
boolean []mark;
int []mp;
int []teams;
int []amount;
int []shortestPathCount;
int n, m, start, enmergency;
public void dijkstra(int s){
//start->s的距离
dist[s] = 0;
amount[s] = teams[s];
//从start开始
int newP = s;
mark[s] = true;
//寻找enmegency:寻找到该节点,停止循环。
while (newP != enmegrgency){
//研究节点newp旁边的i节点,更新最短距离dist【】和最短路线数目pathcount
for (int i = 0; i < n; i++){
//如果mark为false,访问i节点。防止出现环
if (mark[i] == false){
//如果previous的start->i大于现在
if (dist[i] > dist[newP] + mp[newP][i]){
dist[i] = dist[newP] + mp[newP][i];
//gather该市的救援队
amount[i] = amount[newP] + teams[i];
//发生了更新,到i的最短路径数目为newp的最短路径数目
shortestPathCount[i] = shortestPathCount[newP];
}
//如果previous的start->i和现在相等,新增最短路径
else if (dist[i] == dist[newP] + mp[newP][i]){
shortestPathCount[i] += shortestPathCount[newP];
if (amount[i] < amount[newP] + teams[i])
amount[i] = amount[newP] + teams[i];
}
}
}
int distmin = Integer.MAX_VALUE;
//经历一轮状态更新后,寻找dist最小的下一个节点。如果i已经加入子集,不再考虑。
for (int i = 0; i < n; i++){
if (mark[i] == false && dist[i] <distmin){
distmin = dist[i];
newP = i;
}
}
//set mark[] true,before访问节点newP。此时该节点以后不再访问,状态也不再改变。
mark[newP] = true;
}
}
import java.util.Scanner;
import java.io.*;
import java.util.Iterator;
class Emergency
{
int []dist;
boolean []mark;
int []mp;
int []teams;
int []amount;
int []shortestPathCount;
int n, m, start, enmergency;
public void dijkstra(int s){
//start->s的距离
dist[s] = 0;
amount[s] = teams[s];
//从start开始
int newP = s;
mark[s] = true;
//寻找enmegency:寻找到该节点,停止循环。
while (newP != enmegrgency){
//研究节点newp旁边的i节点,更新最短距离dist【】和最短路线数目pathcount
for (int i = 0; i < n; i++){
//如果mark为false,访问i节点。防止出现环
if (mark[i] == false){
//如果previous的start->i大于现在
if (dist[i] > dist[newP] + mp[newP][i]){
dist[i] = dist[newP] + mp[newP][i];
//gather该市的救援队
amount[i] = amount[newP] + teams[i];
//发生了更新,到i的最短路径数目为newp的最短路径数目
shortestPathCount[i] = shortestPathCount[newP];
}
//如果previous的start->i和现在相等,新增最短路径
else if (dist[i] == dist[newP] + mp[newP][i]){
shortestPathCount[i] += shortestPathCount[newP];
if (amount[i] < amount[newP] + teams[i])
amount[i] = amount[newP] + teams[i];
}
}
}
int distmin = Integer.MAX_VALUE;
//经历一轮状态更新后,寻找dist最小的下一个节点。如果i已经加入子集,不再考虑。
for (int i = 0; i < n; i++){
if (mark[i] == false && dist[i] <distmin){
distmin = dist[i];
newP = i;
}
}
//set mark[] true,before访问节点newP。此时该节点以后不再访问,状态也不再改变。
mark[newP] = true;
}
}
public static void main(){
省略
}
0 0
- 1003. Emergency (25)-PAT
- (PAT)1003. Emergency (25)
- PAT 1003. Emergency (25)
- PAT 1003. Emergency (25)
- [PAT]1003. Emergency (25)
- 【PAT】1003. Emergency (25)
- PAT 1003. Emergency (25)
- PAT 1003. Emergency (25)
- PAT 1003. Emergency (25)
- 【PAT】1003. Emergency (25)
- PAT 1003. Emergency (25)
- pat 1003. Emergency (25)
- PAT:1003. Emergency (25)
- PAT:1003. Emergency (25)
- 【PAT】1003. Emergency (25)
- pat 1003. Emergency (25)
- PAT 1003. Emergency (25)
- PAT --- 1003. Emergency (25)
- Unity NGUI和UGUI与模型、特效的层级关系
- VMware技巧汇总
- 学点JS实例-文字滑动(4)
- 站军姿(计算几何 多三角形覆盖面积)
- React Native创建项目时报错:npm ERR! Windows_NT 10.0.10240 错误
- PAT:1003. Emergency (25)
- 05. Loops & Arrays
- noip模拟赛(10.4) 背包(pack)
- Linux 设备驱动篇之I2c设备驱动
- effective stl 第41条:理解ptr_fun/mem_fun/mem_fun_ref的由来
- Redis学习必备知识
- Kali Linux 秘籍 第八章 密码攻击
- Java bean 你所知道的一切
- java实现发送手机短信