栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2515 Height of Water Tower

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2515 Height of Water Tower

#include <cstring> #include <map>#include <cstdio>#include <string>#include <utility>#include <algorithm>using namespace std;#define inf 999999999class point{private:    int x,y,z;public:    point()    {        x=y=z=0;    }    void get()    {        scanf("%d%d%d",&x,&y,&z);    }    inline int height() const    {        return z;    }    inline bool operator ==(const point &that) const    {        return x==that.x&&y==that.y&&z==that.z;    }    inline bool operator <(const point &that) const    {        if(x==that.x){ if(y==that.y) return z<that.z; else return y<that.y;        }        else return x<that.x;    }};point p[2002];map<point,int> mp;bool board[2002][2002];bool mark[2002];int minh[2002];void Dijkstra(int n,int s){    int i,j,k;    for(i=0;i<n;i++){        minh[i]=inf;        mark[i]=false;    }    minh[s]=p[s].height();    for(i=0;i<n;i++){        k=-1;        for(j=0;j<n;j++) if(!mark[j]&&(k==-1||minh[j]<minh[k])) k=j;        mark[k]=1;        for(j=0;j<n;j++) if(!mark[j]&&board[k][j]&&max(minh[k],p[j].height())<minh[j]) minh[j]=max(minh[k],p[j].height());    }}int main(){    int n,m,ff,tt,ans;    point f,t;    while(scanf("%d",&m)!=EOF){        memset(board,0,sizeof(board));        mp.clear();        mp.insert(make_pair(point(),0));        p[0]=point();        n=1;        while(m--){ f.get(); t.get(); if(mp.find(f)==mp.end()){     mp.insert(make_pair(f,n));     p[n]=f;     ff=n++; } else ff=mp[f]; if(mp.find(t)==mp.end()){     mp.insert(make_pair(t,n));     p[n]=t;     tt=n++; } else tt=mp[t]; board[ff][tt]=board[tt][ff]=true;        }        Dijkstra(n,0);        ans=p[0].height();        scanf("%d",&m);        while(m--){ t.get(); tt=mp[t]; if(minh[tt]>ans) ans=minh[tt];        }        printf("%dn",ans);    }}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/374785.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号