POJ 2662 A Walk Through the Forest

本文介绍了一个计算从森林一端到另一端所有可能路径数量的问题。起点编号为1,终点编号为2,要求每一步都更接近终点。通过使用记忆化搜索和Dijkstra算法求解最短路径来实现。

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

Description

Jimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he likes to walk home. To make things even nicer, his office is on one side of a forest, and his house is on the other. A nice walk through the forest, seeing the birds and chipmunks is quite enjoyable.
The forest is beautiful, and Jimmy wants to take a different route everyday. He also wants to get home before dark, so he always takes a path to make progress towards his house. He considers taking a path from A to B to be progress if there exists a route from B to his home that is shorter than any possible route from A. Calculate how many different routes through the forest Jimmy might take.

Input

Input contains several test cases followed by a line containing 0. Jimmy has numbered each intersection or joining of paths starting with 1. His office is numbered 1, and his house is numbered 2. The first line of each test case gives the number of intersections N, 1 < N <= 1000, and the number of paths M. The following M lines each contain a pair of intersections a b and an integer distance 1 <= d <= 1000000 indicating a path of length d between intersection a and a different intersection b. Jimmy may walk a path any direction he chooses. There is at most one path between any pair of intersections.

Output

For each test case, output a single integer indicating the number of different routes through the forest. You may assume that this number does not exceed 2147483647.

Sample Input

5 6
1 3 2
1 4 2
3 4 3
1 5 12
4 2 34
5 2 24
7 8
1 3 1
1 4 1
3 7 1
7 4 1
7 5 1
6 7 1
5 2 1
6 2 1
0

Sample Output

2
4
题意;一个人要从树林一端穿到另一端,起点为1,终点为2,要求: 每次到达新点一定是更加接近终点,问有多少种路径;
思路:记忆化加深搜,开始用dijkstra 求出所有点到终点的最短距离。
优先队列+邻接表
#include<stdio.h>
#include<string.h>
#include<queue>
#define INF 0x1f1f1f
using namespace std;
int head[1002];
struct node
{
    int to,w,next;
}q[3000002];
struct node2
{
    int xu,di;
    bool operator < (node2 t)const
    {
        return t.di<di;
    }
}tt,in;
int tot;
int n,sum;
void add(int s,int t,int wi)
{
    q[tot].to=t;
    q[tot].next=head[s];
    q[tot].w=wi;
    head[s]=tot++;
}
int d[1002];
void dijkstra(int v)
{
    priority_queue<node2>dis;
    int i;
    in.xu=v;
    in.di=0;
    d[v]=0;
    dis.push(in);
    while(!dis.empty())
    {
        tt=dis.top();
        if(tt.xu==1)break;
        dis.pop();
        for(i=head[tt.xu];i;i=q[i].next)
        {
            in.xu=q[i].to;
            in.di=tt.di+q[i].w;
            if(in.di<d[in.xu])
            {
                d[in.xu]=in.di;
                dis.push(in);
            }
        }
        
    }
}
int j[1002];
int dfs(int r)
{
    int i,k=0;
    if(j[r]!=-1)
        return j[r];
    for(i=head[r];i;i=q[i].next)
        if(d[q[i].to]<d[r])
            k+=dfs(q[i].to);
    return j[r]=k;
}
int main()
{
    int i,m,a,b,w;
    while(scanf("%d",&n),n)
    {
        scanf("%d",&m);
        tot=1;
        memset(j,-1,sizeof(j));
        memset(head,0,sizeof(head));
        memset(d,INF,sizeof(d));
        while(m--)
        {
            scanf("%d%d%d",&a,&b,&w);
            add(a,b,w);
            add(b,a,w);
        }
        dijkstra(2);
        j[2]=1;
        printf("%d\n",dfs(1));
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/dream-wind/archive/2012/04/14/2447808.html

内容概要:本文档详细介绍了基于Google Earth Engine (GEE) 构建的阿比让绿地分析仪表盘的设计与实现。首先,定义了研究区域的几何图形并将其可视化。接着,通过云掩膜函数和裁剪操作预处理Sentinel-2遥感影像,筛选出高质量的数据用于后续分析。然后,计算中值图像并提取NDVI(归一化差异植被指数),进而识别绿地及其面积。此外,还实现了多个高级分析功能,如多年变化趋势分析、人口-绿地交叉分析、城市热岛效应分析、生物多样性评估、交通可达性分析、城市扩张分析以及自动生成优化建议等。最后,提供了数据导出、移动端适配和报告生成功能,确保系统的实用性和便捷性。 适合人群:具备一定地理信息系统(GIS)和遥感基础知识的专业人士,如城市规划师、环境科学家、生态学家等。 使用场景及目标:①评估城市绿地分布及其变化趋势;②分析绿地与人口的关系,为城市规划提供依据;③研究城市热岛效应及生物多样性,支持环境保护决策;④评估交通可达性,优化城市交通网络;⑤监测城市扩张情况,辅助土地利用管理。 其他说明:该系统不仅提供了丰富的可视化工具,还集成了多种空间分析方法,能够帮助用户深入理解城市绿地的空间特征及其对环境和社会的影响。同时,系统支持移动端适配,方便随时随地进行分析。用户可以根据实际需求选择不同的分析模块,生成定制化的报告,为城市管理提供科学依据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值