POJ1135_Domino Effect(最短)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8224 | Accepted: 2068 |
Description
to fall down in succession (this is where the phrase ``domino effect'' comes from).
While this is somewhat pointless with only a few dominoes, some people went to the opposite extreme in the early Eighties. Using millions of dominoes of different colors and materials to fill whole halls with elaborate patterns of falling dominoes, they created
(short-lived) pieces of art. In these constructions, usually not only one but several rows of dominoes were falling at the same time. As you can imagine, timing is an essential factor here.
It is now your task to write a program that, given such a system of rows formed by dominoes, computes when and where the last domino falls. The system consists of several ``key dominoes'' connected by rows of simple dominoes. When a key domino falls, all rows
connected to the domino will also start falling (except for the ones that have already fallen). When the falling rows reach other key dominoes that have not fallen yet, these other key dominoes will fall as well and set off the rows connected to them. Domino
rows may start collapsing at either end. It is even possible that a row is collapsing on both ends, in which case the last domino falling in that row is somewhere between its key dominoes. You can assume that rows fall at a uniform rate.
Input
at most one row between any pair of key dominoes and the domino graph is connected, i.e. there is at least one way to get from a domino to any other domino by following a series of domino rows.
The following m lines each contain three integers a, b, and l, stating that there is a row between key dominoes a and b that takes l seconds to fall down from end to end.
Each system is started by tipping over key domino number 1.
The file ends with an empty system (with n = m = 0), which should not be processed.
Output
which is either at a key domino or between two key dominoes(in this case, output the two numbers in ascending order). Adhere to the format shown in the output sample. The test data will ensure there is only one solution. Output a blank line after each system.
Sample Input
2 1
1 2 27
3 3
1 2 5
1 3 5
2 3 5
0 0
Sample Output
System #1
The last domino falls after 27.0 seconds, at key domino 2. System #2
The last domino falls after 7.5 seconds, between key dominoes 2 and 3.
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#define inf 99999999
using namespace std;
int n,m,mmap[510][510],dis[510],vis[510];
void dij()
{
int i,j,u,minn;
for(i=1; i<=n; i++)
{
dis[i]=mmap[1][i];
vis[i]=0;
}
dis[1]=0;
vis[1]=1;
for(i=0; i<n-1; i++)
{
minn=inf;
u=0;
for(j=1; j<=n; j++)
{
if(!vis[j]&&dis[j]<minn)
{
minn=dis[j];
u=j;
}
}
vis[u]=1;
for(j=1; j<=n; j++)
{
if(!vis[j]&&dis[j]>dis[u]+mmap[u][j])
{
dis[j]=dis[u]+mmap[u][j];
}
}
}
}
int main()
{
int i,j,u,v,w,k=1;
while(cin>>n>>m)
{
if(!n&&!m)break; printf("System #%d\n",k++);
if(n==1)
{printf("The last domino falls after 0.0 seconds, at key domino 1.\n\n");
continue;}
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
mmap[i][j]=inf;
mmap[i][j]=0;
}
for(i=0; i<m; i++)
{
cin>>u>>v>>w;
if(mmap[u][v]>w)
mmap[u][v]=mmap[v][u]=w;
}
dij();
double maxx1=0;
int u=0;
for(i=1; i<=n; i++)
{
if(dis[i]>maxx1)
{
maxx1=dis[i];
u=i;
}
}
int a1,a2;
double maxx2=0;
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
double t=(dis[i]+dis[j]+mmap[i][j])/2.0;
if(mmap[i][j]<inf&&maxx2<t)
{
maxx2=t;
a1=i;
a2=j;
}
}
}
if(maxx1>=maxx2)
{
printf("The last domino falls after %.1lf seconds, at key domino %d.\n",maxx1,u);
}
else printf("The last domino falls after %.1lf seconds, between key dominoes %d and %d.\n",maxx2,a1,a2);
printf("\n");
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
POJ1135_Domino Effect(最短)的更多相关文章
- zoj 1298 Domino Effect (最短路径)
Domino Effect Time Limit: 2 Seconds Memory Limit: 65536 KB Did you know that you can use domino ...
- [POJ] 1135 Domino Effect
Domino Effect Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12147 Accepted: 3046 Descri ...
- POJ 1135 -- Domino Effect(单源最短路径)
POJ 1135 -- Domino Effect(单源最短路径) 题目描述: 你知道多米诺骨牌除了用来玩多米诺骨牌游戏外,还有其他用途吗?多米诺骨牌游戏:取一 些多米诺骨牌,竖着排成连续的一行,两 ...
- GooglePlay 首页效果----tab的揭示效果(Reveal Effect) (1)
GooglePlay 首页效果----tab的揭示效果(Reveal Effect) (1) 前言: 无意打开GooglePlay app来着,然后发现首页用了揭示效果,连起来用着感觉还不错. 不清楚 ...
- Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果
Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果 前言: 每次写之前都会来一段(废)话.{心塞...} Google Play首页两个tab背景 ...
- [LeetCode] Minimum Unique Word Abbreviation 最短的独一无二的单词缩写
A string such as "word" contains the following abbreviations: ["word", "1or ...
- [LeetCode] Shortest Word Distance III 最短单词距离之三
This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same as ...
- [LeetCode] Shortest Word Distance II 最短单词距离之二
This is a follow up of Shortest Word Distance. The only difference is now you are given the list of ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
随机推荐
- 【C语言探索之旅】 第二部分第五课:预处理
内容简介 1.课程大纲 2.第二部分第五课: 预处理 3.第二部分第六课预告: 创建你自己的变量类型 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C语 ...
- win7开机直接进入系统系统桌面
在开始搜索栏输入:netplwiz 选中admin用户(也就是你登录的用户名),然后在把上面的勾去掉,点应用,会提示输入用户名和密码,输二次,是一样的密码,如果没设密码,就不用输直接应用,确定就O ...
- ICT工作的思考<两>
2周奋战.我负责的LB昨天完成了最后一个模块.最后20日. 一周早于预期,经理说,出乎他的意料.So 奖励表,昨日,管理人员与我们合作,吃烧烤补补身子.我只想说,最后一个喘息. 这两周的生活确挺忙碌的 ...
- org.eclipse.birt.report.data.oda.jdbc.JDBCException: Missing properties in Connection.open(Propertie
首先查看project的web.xml档"BIRT_RESOURCE_PATH"属性的设置.此属性设置的是"用户资源存放路径.这些资源包含 library 文件,imag ...
- PowerShell 批量导入/导出Active Directory
PowerShell 批量导入/导出Active Directory 近期由于公司要求,须要导入20个供应商.20个客户到AD域中,刚開始手动添�了2个供应商,2个客户.可是感觉费时费 ...
- outlook 当关闭时最小化到任务栏完美的解决方案
近期使用Outlook,但很发现easy退出关闭.不能达到最小化封. 在网上找了很长时间也用outlook on the desktop插件,但该插件安装后的执行错误和被遗弃. 最后,我发现了一个叫k ...
- Android APK反编译详解(非常有用)
如何学习最快呢?无疑是通过研究别人的源代码? 但是,获取别人的源代码,比较困难.本文,仅限于用于学习开发. 这段时间在学Android应用开发,在想既然是用Java开发的应该很好反编译从而得到源代码吧 ...
- 左右v$datafile和v$tempfile中间file#
v$datafile关于存储在文件中的数据视图的信息,v$tempfile查看存储在一个临时文件中的信息. 有两种观点file#现场,首先来看看官方文件的定义: V$DATAFILE This vie ...
- 编程算法基地-2.1利用字符串API
2.1利用字符串API 字符串是Java类型最常用.并且是复合类型 串非常经常用于,其最佳API熟悉文档. 推断串中有没有反复的字符 String s ="abcdebxyz"; ...
- verilog中的有符号数运算
verilog中的有符号数运算 http://hi.baidu.com/lixu1113/item/d00dc095f86aed48f142159a verilog中的有符号数运算 有符号数的计算:若 ...