博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[POJ] 1135 Domino Effect
阅读量:6613 次
发布时间:2019-06-24

本文共 5506 字,大约阅读时间需要 18 分钟。

Domino EffectTime Limit: 1000MS      Memory Limit: 65536KTotal Submissions: 12147        Accepted: 3046DescriptionDid you know that you can use domino bones for other things besides playing Dominoes? Take a number of dominoes and build a row by standing them on end with only a small distance in between. If you do it right, you can tip the first domino and cause all others 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.InputThe input file contains descriptions of several domino systems. The first line of each description contains two integers: the number n of key dominoes (1 <= n < 500) and the number m of rows between them. The key dominoes are numbered from 1 to n. There is 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.OutputFor each case output a line stating the number of the case ('System #1', 'System #2', etc.). Then output a line containing the time when the last domino falls, exact to one digit to the right of the decimal point, and the location of the last domino falling, 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 Input2 11 2 273 31 2 51 3 52 3 50 0Sample OutputSystem #1The last domino falls after 27.0 seconds, at key domino 2.System #2The last domino falls after 7.5 seconds, between key dominoes 2 and 3.SourceSouthwestern European Regional Contest 1996

到每个点的最短路就是推到这个点的最短时间

处理边就用(dis[i]+dis[j]+w)/2更新最大值
然后比较最大值和每个dis里的最大值,大于说明就是在边上推到了结束,否则就是在这个最大值的点上结束的。

特判n=1的点。。。

输出 真的 恶心

为什么 .1lf 就WA .1f 就AC

#include
#include
#include
#include
using namespace std;const int MAXN=505;const int INF=1<<28;int n,m;struct Edge{ int next,to,w;}e[MAXN*MAXN];int ecnt,head[MAXN];inline void add(int x,int y,int w){ e[++ecnt].next = head[x]; e[ecnt].to = y; e[ecnt].w = w; head[x] = ecnt;}bool vis[MAXN];int dis[MAXN];int baned[MAXN];struct Node{ int id,w; bool operator<(const Node &rhs) const{ return w>rhs.w; }};void dij(){ priority_queue
Q; vis[1]=0; for(int i=2;i<=n;i++) dis[i]=INF,vis[i]=0; for(int i=1;i<=n;i++) Q.push(Node{i,dis[i]}); for(int i=1;i<=n;i++){ Node top; do{ top=Q.top() ; Q.pop(); }while(vis[top.id]); int mnid=top.id,mn=top.w; vis[mnid]=1; for(int i=head[mnid];i;i=e[i].next){ int v=e[i].to ; if(dis[v]>mn+e[i].w){ dis[v]=mn+e[i].w ;// baned[v]=mnid; Q.push(Node{v,dis[v]}); } } } }int main(){ int cnt=1; while(cin>>n>>m){// memset(baned,0,sizeof(baned)); if(!n) return 0; ecnt=0; for(int i=1;i<=n;i++) head[i]=0; for(int i=1;i<=m;i++){ int x,y,w; cin>>x>>y>>w; add(x,y,w); add(y,x,w); } dij(); double mx=0.0; double single_mx=-INF; int mxid; for(int i=1;i<=n;i++) { if(single_mx
mx){ mx=(double)(1.0*(dis[i]+dis[v]+e[j].w)/2.0); l=v
=i?v:i; } } } printf("System #%d\n",cnt++); if(n==1){ printf("The last domino falls after 0.0 seconds, at key domino 1.\n\n");// continue; } if(mx<=single_mx){ // The last domino falls after 27.0 seconds, at key domino 2. printf("The last domino falls after %.1f seconds, at key domino %d.\n",mx,mxid); }else{ // The last domino falls after 7.5 seconds, between key dominoes 2 and 3. printf("The last domino falls after %.1f seconds, between key dominoes %d and %d.\n" ,mx,l,r); } printf("\n"); }}

转载于:https://www.cnblogs.com/ghostcai/p/9247473.html

你可能感兴趣的文章
深度学习笔记之CNN(卷积神经网络)基础
查看>>
Hadoop 添加删除数据节点(datanode)
查看>>
ext的window如何隐藏水平滚动条
查看>>
71.8. Run level shell script to start Oracle 10g services on RedHat Enterprise Linux (RHAS 4)
查看>>
SAP QM Transfer of Inspection Stock
查看>>
ORACLE expdp备份与ORA-31693、ORA-02354、ORA-02149
查看>>
嵌入式 详解udev
查看>>
云安全:这也是需要花大钱去建设的部分
查看>>
5G网络不止能1秒下一部电影,它还能够…
查看>>
中国电信集采终端6700万部 金额达1070亿元
查看>>
2016年的十个数据中心故事
查看>>
《Java并发编程的艺术》一一3.3 顺序一致性
查看>>
《设计之外——比修图更重要的111件事》—第1部分3 虚心学习
查看>>
EVCache —— Netflix 的分布式内存数据存储
查看>>
《用友ERP-U8(8.72版)标准财务模拟实训》——1.4 系统管理注册和导入演示账套...
查看>>
springboot docker笔记
查看>>
Modbus RTU 通信工具设计
查看>>
服务化改造实践 | 如何在 Dubbo 中支持 REST
查看>>
【第8章】JVM内存管理
查看>>
ovirt官方安装文档 附录G
查看>>