zoukankan      html  css  js  c++  java
  • hdu 4849 Wow! Such City! 简单最短路

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4849

    理解题意,然后根据公式求出距离

    再套用最短路模板即可

    队友写的~

    #include <cstring>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
    #include <cstdio>
    #include <stack>
    #include <vector>
    #include <queue>
    
    using namespace std;
    
    typedef long long ll;
    typedef pair<ll, int> P;
    #define INF 0x3f3f3f3f
    const double eps = 1e-9;
    const int maxn = 1000;
    const int modx = 5837501;
    const int mody = 9860381;
    const int modz = 8475871;
    ll x[maxn*maxn+10], y[maxn*maxn+10];
    ll z[maxn*maxn+10];
    
    void build(int n, ll x0, ll x1, ll y0, ll y1)
    {
        int N = n*n;
        x[0] = x0; y[0] = y0;
        x[1] = x1; y[1] = y1;
        for(int i = 2; i < N; i++)
        {
            x[i] = (12345 + x[i-1]*23456 + x[i-2]*34567 + (x[i-1]*x[i-2]%modx)*45678)%modx;
            y[i] = (56789 + y[i-1]*67890 + y[i-2]*78901 + (y[i-1]*y[i-2]%mody)*89012)%mody;
        }
        for(int i = 0; i < N; i++)
            z[i] = (x[i]*90123 + y[i]) % modz + 1;
        //cout<<endl;
    }
    ll d[maxn+10];
    
    void Dijkstra(int n)
    {
        priority_queue<P, vector<P>, greater<P> > que;
        fill(d, d+n+1, INF);
        d[0] = 0;
        que.push(make_pair(d[0], 0));
        while(!que.empty())
        {
            P tp = que.top();que.pop();
            int u = tp.second;
            if(d[u] < tp.first)
                continue;
            for(int v = 0; v < n; v++)
            {
                if(v == u)    continue;
                ll dis = z[u*n+v];
                if(d[v] > d[u] + dis)
                {
                    d[v] = d[u]+ dis;
                    que.push(make_pair(d[v], v));
                }
            }
        }
    }
    int main()
    {
        int n,m,x0,x1,y0,y1;
        //freopen("in", "r", stdin);
        while(scanf("%d%d%d%d%d%d", &n, &m, &x0, &x1, &y0, &y1) != EOF)
        {
            build(n,(ll)x0,(ll)x1,(ll)y0,(ll)y1);
            Dijkstra(n);
            ll ans = m;
            for(int i = 1; i < n; i++)
                ans = min(ans, d[i]%m);
            printf("%I64d
    ", ans);
        }
    }
  • 相关阅读:
    实验5 数独游戏界面设计
    实验4 颜色、字符串资源的使用 实验报告
    实验五 操作系统之存储管理
    实验四 主存空间的分配和回收
    实验三 进程调度模拟程序
    实验二作业调度模拟程序(先来先服务(FCFS)调度算法)
    实验八 SQLite数据库操作
    实验七 BindService模拟通信
    实验六 在应用程序中播放音频和视频
    实验五 数独游戏界面设计
  • 原文地址:https://www.cnblogs.com/dishu/p/4518028.html
Copyright © 2011-2022 走看看