From 55e3cf89b6b8a1b3d9133e2e15b06362895e1531 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Tue, 16 Aug 2016 16:20:15 +0800 Subject: [PATCH] Create 1176.cpp --- POJ/1176.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 POJ/1176.cpp diff --git a/POJ/1176.cpp b/POJ/1176.cpp new file mode 100644 index 0000000..1010ec9 --- /dev/null +++ b/POJ/1176.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +#define MAXN 128 +int N,C; +int a[MAXN]; + +void proca() +{ + for(int i=1;i<=N;i++) + a[i]=!a[i]; +} +void procb() +{ + for(int i=1;i<=N;i+=2) + a[i]=!a[i]; +} +void procc() +{ + for(int i=2;i<=N;i+=2) + a[i]=!a[i]; +} +void procd() +{ + for(int i=1;i<=N;i+=3) + a[i]=!a[i]; +} +int isopen[MAXN]; +int isclose[MAXN]; +bool check() + +{ + /// check + for(int i=1;i<=N;i++) + { + if(isopen[i]&&a[i]!=1) return false; + if(isclose[i]&&a[i]!=0) return false; + } + return true; +} +vector ans; +void DFS(int step) +{ + if(step==C) + { + if(check()) + { + string s; + for(int i=1;i<=N;i++) + { + s.push_back(a[i]+'0'); + } + ans.push_back(s); + } + return; + } + proca(); + DFS(step+1); + proca(); + + procb(); + DFS(step+1); + procb(); + + procc(); + DFS(step+1); + procc(); + + procd(); + DFS(step+1); + procd(); +} +int main() +{ + /// Input Start + scanf("%d",&N); + scanf("%d",&C); + if(C>4) C=4-C%2; + int tmp; + while(scanf("%d",&tmp)==1&&tmp!=-1) isopen[tmp]=1; + while(scanf("%d",&tmp)==1&&tmp!=-1) isclose[tmp]=1; + for(int i=1;i<=N;i++) /// 1 ON , 0 OFF + { + a[i]=1; + } + DFS(0); + sort(ans.begin(),ans.end()); + printf("%s\n",ans.at(0).c_str()); + int last=0; + for(size_t i=1;i