nvitation Cards POJ - 1511 (双向堆优化dijk)

 N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case begins with a line containing exactly two integers P and Q, 1 <= P,Q <= 1000000. P is the number of stops including CCS and Q the number of bus lines. Then there are Q lines, each describing one bus line. Each of the lines contains exactly three numbers - the originating stop, the destination stop and the price. The CCS is designated by number 1. Prices are positive integers the sum of which is smaller than 1000000000. You can also assume it is always possible to get from any stop to any other stop.

Output

For each case, print one line containing the minimum amount of money to be paid each day by ACM for the travel costs of its volunteers.

Sample Input

2
2 2
1 2 13
2 1 33
4 6
1 2 10
2 1 60
1 3 20
3 4 10
2 4 5
4 1 50

Sample Output

46
210

往返最短路实质就是邻接表倒置 再跑一遍单源最短路

此题的数据范围十分之大

另外需要注意的是 即使题目保证了数据范围 但还是要用long long

附上代码

#include<cstdio>
#include<algorithm>
#include<queue>
#include<string>
#include<iostream>
#include<list>
#include<stack>
#include<deque>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
int n,m;
struct node
{
    int to;
    int w;
    bool operator > (const node tmpnode)const
    {
        return w>tmpnode.w;
    }
}a1[1000005],a2[1000005];
priority_queue<node ,vector<node >, greater<node > >q;
int dis1[1000005],dis2[1000005];
int first1[1000005],first2[1000005];
int nex1[1000005],nex2[1000005];
int vis[1000005];
void dijk1()
{
    memset(vis,0,sizeof(vis));
    node tmp;
    int temp;
    tmp.to=1,tmp.w=0;
    q.push(tmp);
    dis1[1]=0;
    while(q.size())
    {
        temp=q.top().to;
        q.pop();
        if(vis[temp]==1) continue;
        vis[temp]=1;
        for(int i=first1[temp];i!=-1;i=nex1[i])
        {
            if(dis1[temp]+a1[i].w<dis1[a1[i].to])
            {
                dis1[a1[i].to]=dis1[temp]+a1[i].w;
                tmp.w=dis1[a1[i].to];
                tmp.to=a1[i].to;
                q.push(tmp);
            }
        }
    }
}
void dijk2()
{
    memset(vis,0,sizeof(vis));
    node tmp;
    int temp;
    tmp.to=1,tmp.w=0;
    q.push(tmp);
    dis2[1]=0;
    while(q.size())
    {
        temp=q.top().to;
        q.pop();
        if(vis[temp]==1) continue;
        vis[temp]=1;
        for(int i=first2[temp];i!=-1;i=nex2[i])
        {
            if(dis2[temp]+a2[i].w<dis2[a2[i].to])
            {
                dis2[a2[i].to]=dis2[temp]+a2[i].w;
                tmp.w=dis2[a2[i].to];
                tmp.to=a2[i].to;
                q.push(tmp);
            }
        }
    }
}
int main()
{
    int t;
    scanf("%d",&t);
    int temp1,temp2,temp3;
    while(t--)
    {
        memset(dis1,0x3f,sizeof(dis1));
        memset(first1,-1,sizeof(first1));
        memset(nex1,-1,sizeof(nex1));
        memset(dis2,0x3f,sizeof(dis2));
        memset(first2,-1,sizeof(first2));
        memset(nex2,-1,sizeof(nex2));
        scanf("%d%d",&n,&m);
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d%d",&temp1,&temp2,&temp3);
            a1[i].to=temp2;
            a1[i].w=temp3;
            nex1[i]=first1[temp1];
            first1[temp1]=i;

            a2[i].to=temp1;
            a2[i].w=temp3;
            nex2[i]=first2[temp2];
            first2[temp2]=i;
        }
        dijk1();
        dijk2();
        long long ans=0;
        for(int i=1;i<=n;i++)
            ans+=dis1[i],ans+=dis2[i];
        printf("%lld\n",ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在信号处理领域,DOA(Direction of Arrival)估计是一项关键技术,主要用于确定多个信号源到达接收阵列的方向。本文将详细探讨三种ESPRIT(Estimation of Signal Parameters via Rotational Invariance Techniques)算法在DOA估计中的实现,以及它们在MATLAB环境中的具体应用。 ESPRIT算法是由Paul Kailath等人于1986年提出的,其核心思想是利用阵列数据的旋转不变性来估计信号源的角度。这种算法相比传统的 MUSIC(Multiple Signal Classification)算法具有较低的计算复杂度,且无需进行特征值分解,因此在实际应用中颇具优势。 1. 普通ESPRIT算法 普通ESPRIT算法分为两个主要步骤:构造等效旋转不变系统和估计角度。通过空间平移(如延时)构建两个子阵列,使得它们之间的关系具有旋转不变性。然后,通过对子阵列数据进行最小二乘拟合,可以得到信号源的角频率估计,进一步转换为DOA估计。 2. 常规ESPRIT算法实现 在描述中提到的`common_esprit_method1.m`和`common_esprit_method2.m`是两种不同的普通ESPRIT算法实现。它们可能在实现细节上略有差异,比如选择子阵列的方式、参数估计的策略等。MATLAB代码通常会包含预处理步骤(如数据归一化)、子阵列构造、旋转不变性矩阵的建立、最小二乘估计等部分。通过运行这两个文件,可以比较它们在估计精度和计算效率上的异同。 3. TLS_ESPRIT算法 TLS(Total Least Squares)ESPRIT是对普通ESPRIT的优化,它考虑了数据噪声的影响,提高了估计的稳健性。在TLS_ESPRIT算法中,不假设数据噪声是高斯白噪声,而是采用总最小二乘准则来拟合数据。这使得算法在噪声环境下表现更优。`TLS_esprit.m`文件应该包含了TLS_ESPRIT算法的完整实现,包括TLS估计的步骤和旋转不变性矩阵的改进处理。 在实际应用中,选择合适的ESPRIT变体取决于系统条件,例如噪声水平、信号质量以及计算资源。通过MATLAB实现,研究者和工程师可以方便地比较不同算法的效果,并根据需要进行调整和优化。同时,这些代码也为教学和学习DOA估计提供了一个直观的平台,有助于深入理解ESPRIT算法的工作原理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值