POJ 1135 Domino Effect (Dijkstra 最短路)

本文介绍了一种模拟多米诺骨牌倒下的算法,通过计算找出最后一张倒下的骨牌及其时间。采用Dijkstra算法计算关键骨牌间的最短路径,并判断最终倒下的骨牌位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Domino Effect
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 9335 Accepted: 2325

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

题目链接:http://poj.org/problem?id=1135

题目大意:有n张关键的多米诺骨牌,m条路。从一条路的起点到终点的牌所有倒下须要时间t。计算最后一张倒下的牌在哪。是什么时候

题目分析:两种情况:
1.最后倒下的牌就是某张关键牌,则时间为最短路中的最大值ma1
2.最后倒下的牌在某两张牌之间,则时间为到两张牌的时间加上两张牌之间牌倒下的时间除2的最大值ma2
最后比較m1和m2。若m1大则为第一种情况,否则是另外一种情况

一组例子:
4 4
1 2 5
2 4 6
1 3 5
3 4 7
0 0

答案:
The last domino falls after 11.5 seconds, between key dominoes 3 and 4.

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int const INF = 0x3fffffff;
int const MAX = 505;
int map[MAX][MAX];
int dis[MAX];
bool used[MAX];
int n, m, ca = 1;

void Dijkstra(int v0)
{
    memset(used, false, sizeof(used));
    for(int i = 1; i <= n; i++)
        dis[i] = map[v0][i];
    used[v0] = true;
    dis[v0] = 0;
    for(int i = 0; i < n - 1; i++)
    {
        int u = 1, mi = INF;
        for(int j = 1; j <= n; j++)
        {
            if(!used[j] && dis[j] < mi)
            {
                mi = dis[j];
                u = j;
            }
        }
        used[u] = true;
        for(int k = 1; k <= n; k++)
            if(!used[k] && map[u][k] < INF)
                dis[k] = min(dis[k], dis[u] + map[u][k]);
    }
    double ma1 = -1, ma2 = -1;
    int pos, pos1, pos2;
    for(int i = 1; i <= n; i++)
    {
        if(dis[i] > ma1)
        {
            ma1 = dis[i];
            pos = i;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(map[i][j] < INF && (dis[i] + dis[j] + map[i][j]) / 2.0 > ma2)
            {
                ma2 = (dis[i] + dis[j] + map[i][j]) / 2.0;
                pos1 = i;
                pos2 = j;
            }
        }
    }
    if(ma1 < ma2)
        printf("The last domino falls after %.1f seconds, between key dominoes %d and %d.\n\n", ma2, pos1, pos2);
    else
        printf("The last domino falls after %.1f seconds, at key domino %d.\n\n", ma1, pos);
        
}

int main()
{
    while(scanf("%d %d", &n, &m) != EOF && (n + m))
    {
        for(int i = 1; i <= n; i++)
        {
            dis[i] = INF;
            for(int j = 1; j <= n; j++)
                map[i][j] = INF;
        }
        for(int i = 0; i < m; i++)
        {
            int u, v, w;
            scanf("%d %d %d", &u, &v, &w);
            map[u][v] = w;
            map[v][u] = w;
        }
        printf("System #%d\n", ca ++);
        Dijkstra(1);
    }
}


内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值