Emergency(山东省第一届ACM省赛)
Emergency
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
Now, she is facing an emergency in her hometown:
Her mother is developing a new kind of spacecraft. This plan costs enormous energy but finally failed. What’s more, because of the failed project, the government doesn’t have enough resource take measure to the rising sea levels caused by global warming, lead to an island flooded by the sea.
Dissatisfied with her mother’s spacecraft and the government, civil war has broken out. The foe wants to arrest the spacecraft project’s participants and the “Chief criminal” – Kudo’s mother – Doctor T’s family.
At the beginning of the war, all the cities are occupied by the foe. But as time goes by, the cities recaptured one by one.
To prevent from the foe’s arrest and boost morale, Kudo and some other people have to distract from a city to another. Although they can use some other means to transport, the most convenient way is using the inter-city roads. Assuming the city as a node and an inter-city road as an edge, you can treat the map as a weighted directed multigraph. An inter-city road is available if both its endpoint is recaptured.
Here comes the problem
Given the traffic map, and the recaptured situation, can you tell Kudo what’s the shortest path from one city to another only passing the recaptured cities?
输入
The input consists of several test cases.
The first line of input in each test case contains three integers N (0<N≤300), M (0<M≤100000) and Q (0<Q≤100000), which represents the number of cities, the numbers of inter-city roads and the number of operations.
Each of the next M lines contains three integer x, y and z, represents there is an inter-city road starts from x, end up with y and the length is z. You can assume that 0<z≤10000.
Each of the next Q lines contains the operations with the following format:
a) 0 x – means city x has just been recaptured.
b) 1 x y – means asking the shortest path from x to y only passing the recaptured cities.
The last case is followed by a line containing three zeros.
输出
For each operation 0, if city x is already recaptured (that is,the same 0 x operation appears again), print “City x is already recaptured.”
For each operation 1, if city x or y is not recaptured yet, print “City x or y is not available.” otherwise if Kudo can go from cityx to city y only passing the recaptured cities, print the shortest path’s length; otherwise print “No such path.”
Your output format should imitate the sample output. Print a blank line after each test case.
示例输入
3 3 6
0 1 1
1 2 1
0 2 3
1 0 2
0 0
0 2
1 0 2
1 2 0
0 2 0 0 0
示例输出
Case 1:
City 0 or 2 is not available.
3
No such path.
City 2 is already recaptured.
解题思路:
开始忘了用多源最短路了,于是乎SPFA果断TL
用floyd最短路就好了,由于点很少,所以直接矩阵保存就好了。。
#include <iostream>
#include <stdio.h>
#include <queue>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;
#define MAX 500
#define INF 0x3f3f3f3f
int mmap[MAX][MAX];
int nodeMark[MAX];
int main (){
int u,v,w;
int N,M,Q,cnt=1; while(~scanf("%d%d%d",&N,&M,&Q)&&!(N==0&&M==0&&Q==0)){
printf("Case %d:\n",cnt++);
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
mmap[i][j]=( i==j ? 0 : INF);
memset(nodeMark,0,sizeof(nodeMark)); for(int i=0;i<M;i++){
scanf("%d%d%d",&u,&v,&w);
mmap[u][v]=min(w,mmap[u][v]);
} int x,y,op;
for(int i=0;i<Q;i++){
scanf("%d",&op);
if(op){
scanf("%d%d",&x,&y);
if(nodeMark[x]==0||nodeMark[y]==0){
printf("City %d or %d is not available.\n",x,y);
}
else{
if(mmap[x][y]==INF) printf("No such path.\n");
else printf("%d\n",mmap[x][y]);
}
}
else{
scanf("%d",&x);
if(nodeMark[x]) printf("City %d is already recaptured.\n",x);
else
{
nodeMark[x]=1;
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
mmap[i][j]=min(mmap[i][x]+mmap[x][j],mmap[i][j]);
}
}
}
printf("\n");
}
return 0;
}
Emergency(山东省第一届ACM省赛)的更多相关文章
- Shopping(山东省第一届ACM省赛)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- Balloons(山东省第一届ACM省赛)
Balloons Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Both Saya and Kudo like balloons ...
- 山东省第一届ACM省赛
ID PID Title Accepted Submit A 2151 Phone Number 22 74 B 2159 Ivan comes again! 1 17 C 2158 Hello ...
- Emergency(山东省第一届ACM程序设计真题+Floyd算法变型)
题目描述 Kudo’s real name is not Kudo. Her name is Kudryavka Anatolyevna Strugatskia, and Kudo is only h ...
- 2010山东省第一届ACM程序设计竞赛
休眠了2月了 要振作起来了!!... http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2155 因 ...
- sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)
题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量) ...
- sdut 2159 Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛) 线段树+离散
先看看上一个题: 题目大意是: 矩阵中有N个被标记的元素,然后针对每一个被标记的元素e(x,y),你要在所有被标记的元素中找到一个元素E(X,Y),使得X>x并且Y>y,如果存在多个满足条 ...
- 2010年山东省第一届ACM大学生程序设计竞赛 Balloons (BFS)
题意 : 找联通块的个数,Saya定义两个相连是 |xa-xb| + |ya-yb| ≤ 1 ,但是Kudo定义的相连是 |xa-xb|≤1 并且 |ya-yb|≤1.输出按照两种方式数的联通块的各数 ...
- Hello World! 2010年山东省第一届ACM大学生程序设计竞赛
Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...
随机推荐
- [转] Loren on the Art of MATLAB
http://blogs.mathworks.com/loren/2007/03/01/creating-sparse-finite-element-matrices-in-matlab/ Loren ...
- 在ASP.NET MVC中,使用Bundle来打包压缩js和css
该总结参考博文地址:http://www.cnblogs.com/xwgli/p/3296809.html 1.首先了解Bundle的作用:Bundles用于打包CSS和javascript脚本文件, ...
- 使用canvas元素-art方法绘制圆弧
最近在学习HTML5,发现canvas真的很棒,canvas元素是一种可供绘图的平面,我们用JavaScript对它进行配置和操作.我这里说一下arc方法绘制圆弧,顺便提一下涉及到的基础知识. 首先看 ...
- You need to use a Theme.AppCompat theme (or descendant) with this activity
经过本人的经验和在网上查找,有2种方法可以解决. 解决步骤已经写到我的公众号,二维码在下面. 欢迎观看我的CSDN学院课程,地址:http://edu.csdn.net/course/detail/2 ...
- 使用Githua管理代码
原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 1.安装配置git服务器 a.安装ssh,因为git是基于ssh协议的,所以必须先装ssh: ...
- org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection 原因
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection 可能出现的原因 ...
- 自建yum源及分组安装
最近在研究一套自动化运维方向的框架,在想到远程安装软件包的时候,觉得有yum支持会更方便一些.主要思路是把程序员写的代码或程序打包成rpm,然后提交到自建yum源,并实现按组安装,本地yum源实现步骤 ...
- 跟我学Windows Azure 三 使用vs2013创建windows azure web site
首先我们需要登陆我们的windows azure上,然后访问 https://manage.windowsazure.cn/publishsettings/index 他会让我们下载我们的订阅证书文件 ...
- HTTP 协议中GET和POST到底有哪些区别
HTTP 定义了与服务器交互的不同方法,最常用的有4种,Get.Post.Put.Delete,如果我换一下顺序就好记了,Put(增),Delete(删),Post(改),Get(查),即增删改查,下 ...
- DTO对象
在EF中,EF生成的对象都是代理对象,这些对象看上去是实体类对象,但是其实都是EF封装好的代理类对象.所以调用EF查询得到的代理类对象有继承于实体对象,所以可以用实体类对象来接收返回的代理类对象.EF ...