stl(图论鬼畜题)
来源:互联网 发布:linux copy命令不覆盖 编辑:程序博客网 时间:2024/05/22 15:11
论stl的妙用
#include<bits/stdc++.h>#define inf 0x7fffffff#define ll long long#define ull unsigned long longusing namespace std;const int mod =1e4+7;const ll INF=1e18;typedef pair<int ,int > P;const int maxn=6e5+5;int n,m,k;struct edge{ int to,cost; edge(){} edge(int to,int cost):to(to),cost(cost){ }};vector<edge>G[maxn];int d[maxn];P p[maxn];//point x,ymap <P,int > mp;//离散化 int dx[4]={0,0,1,-1};int dy[4]={1,-1,0,0};void dijkstra(int s){ priority_queue<P,vector<P>,greater<P> >q; fill(d,d+maxn,inf); d[s]=0; q.push(P(0,s)); while(!q.empty()) { P p=q.top(); q.pop(); int v=p.second; if(d[v]<p.first) continue; for(int i=0;i<G[v].size();i++) { edge e=G[v][i]; if(d[e.to]>d[v]+e.cost){ d[e.to]=d[v]+e.cost; q.push(P(d[e.to],e.to)); } } }}int main(){ cin>>n>>m>>k; int dd=1e4+5 ; mp.clear(); for(int i=1;i<=k;i++) { int r,c; scanf("%d%d",&r,&c); //i->r(v=1) 横向纵向边改dd G[i].push_back(edge(r+dd,1)); G[i].push_back(edge(c+dd*2,1)); G[i].push_back(edge(r+1+dd,1)); G[i].push_back(edge(r-1+dd,1)); G[i].push_back(edge(c+dd*2+1,1)); G[i].push_back(edge(c+dd*2-1,1)); G[r+dd].push_back(edge(i,0)); G[c+dd*2].push_back(edge(i,0)); G[r+1+dd].push_back(edge(i,0)); G[r-1+dd].push_back(edge(i,0)); G[c+dd*2+1].push_back(edge(i,0)); G[c+dd*2-1].push_back(edge(i,0)); p[i]=P(r,c); mp[P(r,c)] =i; } //if(k.around==else k) k->else k=0 for(int i=1;i<=k;i++) { for(int j=0;j<4;j++) { int x=p[i].first+dx[j]; int y=p[i].second+dy[j]; if(mp.find(P(x,y))!=mp.end()) G[i].push_back(edge(mp[P(x,y)],0)); } } //if(n,m)is k ,then m,n =0 if(mp.find(P(n,m))==mp.end()){ G[n+dd].push_back(edge(k+1,0)); G[m+2*dd].push_back(edge(k+1,0)); } int ans; dijkstra(mp[P(1,1)]); if(mp.find(P(n,m))==mp.end()){ ans=d[k+1]; } else ans=d[mp[P(n,m)]]; if(ans==inf) ans=-1; cout<<ans<<endl;}代码是抄的
阅读全文
1 0
- stl(图论鬼畜题)
- stl
- stl
- STL
- STL
- STL
- STL
- STL
- STL
- STL
- stl
- STL
- STL
- STL
- STL
- STL
- STL
- STL
- volatile关键字总结
- laravel5.4系列之laravel下的伪造跨站请求
- 往GitHub上传东西,试了各种方法都不成功,可能是Email设置的问题
- 面向对象的程序设计思想
- 树链剖分总结
- stl(图论鬼畜题)
- ES6之变量的解构赋值--读书笔记
- ListView的Item为动态布局时双Holder的实现
- form表单的post,get提交方式分析以及产生的乱码问题
- 【java开发系列】—— struts2简单入门示例
- Unity Learning for Day 26
- C++类和对象、四个默认成员函数、运算符重载
- mysql误删用户表数据怎么找回用户
- 增加DataFrame打印宽度