[CSP2019-JX] walk solving report

[CSP2019-JX] Walking

Subject to the effect

Has a length \ (L \) cycloalkyl \ ((2 \ Le L \ Le 10 ^. 9) \) ,
with a ring \ (n-\) individual, \ (m \) exit \ ((1 \ le n-, m \ Le 2 \ ^ 10 Times. 5) \) .

The provisions of the first exit location \ (0 \) , and "the first from the exit to" "reach the first intersection are moving away from a clockwise direction" is defined as.
Everyone has two properties \ (t_i, \ x_i \) , represent the forward direction of the person's ( \ (0 \) is counterclockwise, \ (1 \) clockwise), and the first person to exit a distance.
each outlet there are two attributes \ (lim_i, \ a_i \) , respectively, the number of the export restrictions (that is, how many people the most from this exit out), and the first to export from exports.

Within each unit time, everyone will move a unit distance toward their forward direction,
if a person \ (i \) reached a number of people not reached the upper limit of the export \ (J \) , he will exit from this out, then \ (k [i] = J \) .
in particular, if two people reach out to one person only one exit, a small number of the person you can go out.

The final output \ (i \ times k [i ] \) of the exclusive OR and that
\ [(1 \ times k [ 1]) \ oplus (2 \ times k [2]) \ oplus \ dots \ oplus (n \ K Times [n-]) \]
(Note: \ (\ Oplus \) is an exclusive oR symbol)

Thinking

\ (O (N ^ 2) \) 52Pts

First of all, the idea is the most violent of large simulation, each to each individual to shift his direction of movement of a cell, and then small to large sweep again, Behold individuals can go out.

Can be found, in fact, we just need to find him from the next nearest outlet that person, remember him away from the exit of \ (mind \) , the owner moving forward \ (mind \) units from the line.
Of course, there may be the man to the exit, we found that exports have been filled, then we need to look for his next exit, which is one of the most inferior achieve \ (O (n) \) operations, so then the complexity is likely to degenerate into \ (O (the n-^ 3) \) .
so, we need to use (two-way) disjoint-set optimization at this process, the total complexity is \ (O (\ alpha n ^ 3) \) .

But also noted that not every time so that at least one person out, because the current export recently pointed to the man he had been filled from the outlet, so the complexity should be \ (O (metaphysics \ times \ alpha n ^ 3) \)

In the following code.

Code

\ (O (N ^ 2) \) 52Pts



#include<bits/stdc++.h>
using namespace std;
const int N=1e3+7;
const int inf=0x3f3f3f3f;
int n,m,L,d[N],nxt[N],le[N],ri[N],ans,a[N],x[N],minx=inf,nm,nn,lim[N];
bool t[N],gon[N];
int exi[N];
int dis(int i,int j){
  if(!j) return inf;
  int di=abs(x[i]-a[j]);
  if((a[j]>x[i]&&t[i])||(a[j]<x[i]&&!t[i])) di=L+1-di;
  return di;
}
int fl(int x){ return le[x]==x ?x :le[x]=fl(le[x]); }
int fr(int x){ return ri[x]==x ?x :ri[x]=fr(ri[x]); }
int main(){
  \\freopen("walk.in","r",stdin);
  \\freopen("walk.out","w",stdout);
  cin>>n>>m>>L;
  for(int i=2;i<=m;i++){
    scanf("%d",&a[i]);
    le[i]=ri[i]=i;
  }
  le[1]=ri[1]=1;
  for(int i=1;i<=m;i++) scanf("%d",&lim[i]);
  for(int i=1;i<=n;i++){
    scanf("%d%d",&t[i],&x[i]);
    for(int j=1;j<=m;j++)
      if(dis(i,j)<dis(i,nxt[i])) nxt[i]=j;
    minx=min(minx,dis(i,nxt[i]));
  }
  while(nm<m&&nn<n){
    int mind=minx; minx=inf;
    for(int i=1;i<=n;i++){
      if(gon[i]) continue;
      if(t[i]) x[i]-=mind;
      else x[i]+=mind;
      if(x[i]<0) x[i]+=L+1;
      else if(x[i]>L) x[i]-=L+1;
      if(x[i]==a[nxt[i]]){
    if(!lim[nxt[i]]){
      int tmp=0;
      while(!lim[nxt[i]]){
        if(t[i]){ le[tmp]=nxt[i]; nxt[i]=fl(nxt[i])-1; }
        else{ ri[tmp]=nxt[i]; nxt[i]=fr(nxt[i])+1; }
        if(!nxt[i]) nxt[i]=m;
        if(nxt[i]>m) nxt[i]=1;
        tmp=nxt[i];
      }
    }
    else{
      lim[nxt[i]]--;
      if(!lim[nxt[i]]) nm++;
      gon[i]=1; nn++;
      ans^=i*nxt[i];
      exi[i]=nxt[i];
    }
      }
      if(!gon[i]) minx=min(minx,dis(i,nxt[i]));
    }
  }
  printf("%d\n",ans);
  //for(int i=1;i<=n;i++) printf("%d ",exi[i]); putchar('\n');
  return 0;
}

Guess you like

Origin www.cnblogs.com/brucew-07/p/12039937.html