ZOJ 1298_Domino Effect
题意:
多米诺骨牌效应:若干个关键牌相连,关键牌之间含有普通牌,关键牌倒下后其所在的行的普通牌全部倒下。求从推倒1号关键牌开始,最终倒下的牌的位置及时间。
分析:
最终倒下的牌的位置有两种情况,要么是正好为关键牌,要么是在两个关键牌之间的普通牌。前者可以利用最短路求出每个关键牌倒下的时间,而各行普通牌全部倒下的时间为该行两个关键牌倒下时间与该行从一端倒向另一端的时间和的一半,即 (t[i]+t[j]+e[i][j])/2,选出两种情况的最大值进行比较,两者中较大值即为多米诺骨牌完全倒下的时间。
代码:
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
#define rep(i,a,n) for(int i =(a); i < (n); i++)
#define sa(n) scanf("%d",&(n))
int n;
const int maxn=550;
const int INF=0x3fffffff;
int t[maxn],s[maxn],e[maxn][maxn];
void dijkstra()
{
int u;
rep(i,0,n){
t[i]=e[0][i];s[i]=0;
}
t[0]=0;
rep(i,0,n-1){
int mins = INF;
rep(j,0,n){
if(!s[j]&&t[j]<mins){
u=j;
mins=t[j];
}
}
s[u]=1;
rep(k,0,n){
if(!s[k]&&e[u][k]<INF)
t[k]=min(t[k],e[u][k]+t[u]);
}
}
}
int main(void)
{
int m,c=1;
int a,b,l;
sa(n);sa(m);
while(n!=0||m!=0){
fill(t,t+maxn,INF);
rep(i,0,n) rep(j,0,n) e[i][j]=INF;
rep(i,0,m){
sa(a);sa(b);sa(l);
e[a-1][b-1]=e[b-1][a-1]=l;
}
dijkstra();
double maxtime=0;
int p=1;
rep(i,0,n){
if(maxtime<t[i]){
maxtime=t[i];
p=i+1;
}
}
double time,emax=0;
int p1,p2;
rep(i,0,n){
rep(j,0,n){
if(e[i][j]<INF){
time=(t[i]+t[j]+e[i][j])/2.0;
if(time>emax){
emax=time;
p1=i+1;p2=j+1;
}
}
}
}
printf("System #%d\n",c++);
if(maxtime<emax)
printf("The last domino falls after %.1f seconds, between key dominoes %d and %d.\n\n",emax,p1,p2);
else
printf("The last domino falls after %.1f seconds, at key domino %d.\n\n",maxtime,p);
sa(n);sa(m);
}
return 0;
}
ZOJ 1298_Domino Effect的更多相关文章
- zoj 1298 Domino Effect (最短路径)
Domino Effect Time Limit: 2 Seconds Memory Limit: 65536 KB Did you know that you can use domino ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- ZOJ 3777-Problem Arrangement(状压DP)
B - Problem Arrangement Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %l ...
- GooglePlay 首页效果----tab的揭示效果(Reveal Effect) (1)
GooglePlay 首页效果----tab的揭示效果(Reveal Effect) (1) 前言: 无意打开GooglePlay app来着,然后发现首页用了揭示效果,连起来用着感觉还不错. 不清楚 ...
- Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果
Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果 前言: 每次写之前都会来一段(废)话.{心塞...} Google Play首页两个tab背景 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
随机推荐
- 关于springMVC传参问题
今天写项目,碰到一个以前灭有注意到的问题,一般情况下使用springMVC @Controller注解之后,被此注解标记的方法的参数名只需要跟页面表单的标签的name的值相同即可拿到页面的值,但是如果 ...
- bootstrap框架栅格系统使用
使用的前端框架 bootstrap框架 Bootstrap是一个响应式的框架 我们在使用的时候主要使用的是它的网格系统, 1.bootstrap布局 布局容器:.container(用于固定宽度并支 ...
- LN : leetcode 118 Pascal's Triangle
lc 118 Pascal's Triangle 118 Pascal's Triangle Given numRows, generate the first numRows of Pascal's ...
- [BZOJ1088][SCOI2005]扫雷Mine DP
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1088 记录下每一个格子对应左边格子放的雷的情况,然后dp转移就好了. #include&l ...
- 了解移动用户的隐私期望:一种基于推荐的Crowdsourcing方法
应学习之需,最近一段时间阅读了一篇论文,特写下总结,若有纰漏,还望指出. 目录 引言 推荐机制 实现 评估 心得 1.1 为什么要了解移动用户的隐私期望 1.移动设备的广泛使用存在一些潜在的隐私威胁和 ...
- txt通过 vb编程导入 excel
Private Sub CommandButton1_Click() '按钮触发, '按钮触发,目前支持ASNI文本的数据, 单行 fileToOpen = Application.GetOpenFi ...
- bdflush - 将dirty缓存写回到磁盘的核心守护进程
总览(SYNOPSIS) bdflush [opt] 描述(DESCRIPTION) bdflush 被用来启动核心守护进程将内存中的dirty缓存写到磁盘上.真正清洁工作是一个核心程序完成的. bd ...
- vue中滚动页面,改变样式&&导航栏滚动时,样式透明度修改
vue中滚动页面,改变样式&&导航栏滚动时,样式透明度修改.vue <div class="commonHeader" v-bind:class=" ...
- linux 小键盘 数字键盘 wiki
https://wiki.archlinux.org/index.php/Activating_Numlock_on_Bootup_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96 ...
- 采用Qt快速绘制多条曲线(折线),跟随鼠标动态显示线上点的值(基于Qt的开源绘图控件QCustomPlot进行二次开发)
QCustomPlot是一个开源的基于Qt的第三方绘图库,能够绘制漂亮的2D图形. QCustomPlot的官方网址:https://www.qcustomplot.com/ 从官网下载QCustom ...