poj 1135 Domino Effect

Domino Effect
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 12325 Accepted: 3083

Description

Did 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.

Input

The 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.

Output

For 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 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

Southwestern European Regional Contest 1996

思路:最后倒下的牌有两种情形

一  、最后倒下的是关键牌,其时间和位置就是第一张关键牌到其他关键牌的最短路径的最大值 记作max1

二、最后倒下的是普通牌,其时间和位置就是两张关键牌之间的某张普通牌,其时间为max2=(d[i]+d[j]+G[i][j])/2.0  G[i][j]表示的就是两张相邻关键牌之间倒下所需要的时间   

如果max2>max1 就是第二种情况  否则就是第一种情况

#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn=505;
const double INF=10000000;
struct edge{
    int to;
    int cost;
}e;
int caseno=1;
typedef pair<int,int> P;//first 表示最短距离  second表示顶点的编号
int n,m;
vector<edge> G[maxn];
double d[maxn];
void dijkstra(int s)
    {
        priority_queue<P,vector<P>,greater<P> > que;
        fill(d,d+n+1,INF);//fill 要改成d+n+1才行  因为从1开始计数
        d[s]=0.0;
        que.push(P(0.0,s));
        while(!que.empty())
            {
                P p=que.top();
                que.pop();
                int v=p.second;
                if(d[v]<p.first) continue;
                for (int i=0;i<G[v].size();i++)
                    {
                        edge e=G[v][i];
                        if(d[e.to]>d[v]+e.cost)
                            {
                                d[e.to]=d[v]+e.cost;
                                que.push(P(d[e.to],e.to));
                            }
                    }
            }
    }

int main()
    {
        int a,b,c;
        while(cin>>n>>m)
            {
                if(n==0&&m==0) break;
                double maxn1=-1,maxn2=-1;
                for(int i=1;i<=n;i++) G[i].clear();
                while(m--)
                    {
                        scanf("%d",&a);
                        scanf("%d%d",&b,&c);
                        e.to=b;
                        e.cost=c;
                        G[a].push_back(e);
                        e.to=a;
                        G[b].push_back(e);//重点强调  这里wa了我一个小时  无向图所以要进行两次赋值
                    }
                dijkstra(1);
                int m1=0,m2=0,m3=0;
                for(int i=2;i<=n;i++)
                    {
                        if(maxn1<d[i])
                        {
                            maxn1=d[i];
                            m1=i;
                        }
                        //cout<<d[i]<<endl;
                    }
                //cout<<maxn1<<endl;
                for (int i=0;i<=n;i++)
                    {
                        for(int j=0;j<G[i].size();j++)//从i到j的之间的距离
                            {
                                e=G[i][j];
                                double temp=(e.cost+d[e.to]+d[i])/2.0;
                                if(maxn2<temp)
                                {
                                    maxn2=temp;
                                    m2=i;
                                    m3=e.to;
                                }
                            }
                    }
                if(n==1) {maxn1=0.0;m1=1;}
                if(maxn2>maxn1)
                {
                    if(m2>m3) swap(m2,m3);
                    printf("System #%d\nThe last domino falls after %.1f seconds, between key dominoes %d and %d.\n\n",caseno++,maxn2,m2,m3);
                }
                else
                    printf("System #%d\nThe last domino falls after %.1f seconds, at key domino %d.\n\n",caseno++,maxn1,m1);
            }
            return 0;
    }

资源下载链接为: https://pan.quark.cn/s/3d8e22c21839 随着 Web UI 框架(如 EasyUI、JqueryUI、Ext、DWZ 等)的不断发展与成熟,系统界面的统一化设计逐渐成为可能,同时代码生成器也能够生成符合统一规范的界面。在这种背景下,“代码生成 + 手工合并”的半智能开发模式正逐渐成为新的开发趋势。通过代码生成器,单表数据模型以及一对多数据模型的增删改查功能可以被直接生成并投入使用,这能够有效节省大约 80% 的开发工作量,从而显著提升开发效率。 JEECG(J2EE Code Generation)是一款基于代码生成器的智能开发平台。它引领了一种全新的开发模式,即从在线编码(Online Coding)到代码生成器生成代码,再到手工合并(Merge)的智能开发流程。该平台能够帮助开发者解决 Java 项目中大约 90% 的重复性工作,让开发者可以将更多的精力集中在业务逻辑的实现上。它不仅能够快速提高开发效率,帮助公司节省大量的人力成本,同时也保持了开发的灵活性。 JEECG 的核心宗旨是:对于简单的功能,可以通过在线编码配置来实现;对于复杂的功能,则利用代码生成器生成代码后,再进行手工合并;对于复杂的流程业务,采用表单自定义的方式进行处理,而业务流程则通过工作流来实现,并且可以扩展出任务接口,供开发者编写具体的业务逻辑。通过这种方式,JEECG 实现了流程任务节点和任务接口的灵活配置,既保证了开发的高效性,又兼顾了项目的灵活性和可扩展性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值