BZOJ4070: [Apio2015] The skyscrapers of Jakarta

Source: Internet
Author: User

Idea  {
For every dog on the floor . The most intuitive method is to split a point into an N -Dog Point, and then the shortest way.
However, I was also drunk in the blast space.
So we're going to use a tune-up of the chunking.
Should be the connected state of each point. Just a little bit.
Divide a building into 1- block long layers, and for any dog with the same number of layers, you can  walk in a high-altitude mess.
But what is the length of the p> block? ------ directly connected to the edge.
Then YY , dealing with each dog's activation relationship. SPFA can do it.
}

 

#include <bits/stdc++.h> #define RG register#define il inline #define N 5500000#define Inf 2#define U unsigned short#d Efine POS (i,j) (i*n+j) using namespace std;struct ed{int nxt,to,c;} E[30005*500];int head[30005*105],dis[30005*105],n,m,q,b,s,t;bool in[30005*105];int tot;void Add (int u,int v,int c) {e[ tot].nxt=head[u];e[tot].to=v;e[tot].c=c;head[u]=tot++;} void Add (int u,int v,int c) {Add (U,v,c), add (v,u,c);}  void Spfa () {queue<int>que;memset (dis,inf,sizeof (DIS)); int ss=dis[t];  Que.push (s), in[s]=true,dis[s]=0;    while (!que.empty ()) {int U=que.front (); Que.pop (); in[u]=false; for (int i=head[u];i!=-1;i=e[i].nxt) if (dis[e[i].to]>dis[u]+e[i].c) {int v=e[i].to;dis[v]=dis[u]+e[i].c;if (!in[v      ]) Que.push (v), in[v]=true;  }}if (DIS[T]==SS) cout<< "-1"; else cout<<dis[t];}  int main () {freopen ("skyscraper.in", "R", stdin);  Freopen ("Skyscraper.out", "w", stdout);  memset (head,-1,sizeof (head)); cin>>n>>m;  U int len=min ((int) sqrt (n), 100); for (RG int i=1;i<=len;++i) for (int j=1;j<=n;++j) Add (POS (i,j), j,0);  for (RG int i=1;i<=len;++i) for (int j=1;j<=n-i;++j) ADD (POS (I,J), POS (i,j+i), 1);    for (RG int i=1;i<=m;++i) {int b,p;    cin>>b>>p;b++;    if (i==1) s=b;if (i==2) t=b;    if (P<=len) Add (B,pos (p,b), 0);      else {for (int j=1;j*p+b<=n;++j) Add (B,B+J*P,J);    for (int j=1;b-j*p>0;++j) Add (B,B-J*P,J);  }}SPFA (); return 0;}

  

 

BZOJ4070: [Apio2015] The skyscrapers of Jakarta

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.