P3584 [POI2015]LAS

题面

https://www.luogu.org/problem/P3584

题解

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

bool f[1000050][2][2][2];
int a[1000050],ans[1000050],n,opt;
int vis[1000050][2][2][2];

int suc(int x){
  if (x==n) return 1; else return x+1;
}

bool dfs(int x,int y,int z,int now) {
  if (vis[now][x][y][z]==opt) {
    if (now==1) return true; else return false;
  }
  else vis[now][x][y][z]=opt;

  int i;
  for (i=0;i<2;i++) 
    if (f[suc(now)][y][z][i] && dfs(y,z,i,suc(now))) { 
      ans[now]=y; 
      //cout<<x<<" "<<y<<" "<<z<<" "<<now<<endl;
      return true;
    }
  return false;
}

int main(){
  int i,j,x,y,z;
  double l,r;
  scanf("%d",&n);
  for (i=1;i<=n;i++) scanf("%d",&a[i]);
  for (i=1;i<=n;i++)
    for (x=0;x<2;x++)
      for (y=0;y<2;y++) {
        if (x==1) l=a[i]/2.0; else l=a[i];
        if (y==0) r=a[suc(i)]/2.0; else r=a[suc(i)];
        if (r>=l) f[i][x][1][y]=true;
        if (l>=r) f[i][x][0][y]=true;
        //cout<<x<<" "<<y<<" "<<l<<" "<<r<<endl;
        //cout<<f[i][x][0][y]<<f[i][x][1][y]<<endl;
      }
  for (i=1;i<=n;i++)
    for (x=0;x<2;x++)
      for (y=0;y<2;y++) 
        for (z=0;z<2;z++) ;//if (f[i][x][y][z]) cout<<i<<" "<<x<<" "<<y<<" "<<z<<endl;

  for (x=0;x<2;x++)
    for (y=0;y<2;y++) 
      for (z=0;z<2;z++) if (f[1][x][y][z]) {
        opt=x*4+y*2+z+1;
        if (dfs(x,y,z,1)) {
          for (j=1;j<=n;j++) if (ans[j]) printf("%d ",suc(j)); else printf("%d ",j);
          return 0;
        }
      }
  puts("NIE");
}

 

posted @ 2019-08-29 00:01  HellPix  阅读(209)  评论(0编辑  收藏  举报