Question chain description
To assign a laser to a specified receiver and maximize the number, you only need to place a plane mirror at N * n positions.
Sol
We found that one row either put '/' or only '\', and answer = n | answer = n-1, which can be merged backwards.
Description
#include<bits/stdc++.h>#define N 1006using namespace std;int n,a[N],last;char ans[N][N];signed main () { scanf("%d",&n); for (int i=1;i<=n;i++) { scanf("%d",a+i); if (a[i]!=i) last=i; } if (last) { char x=‘/‘, y=‘\\‘; for(int i=n;i;--i){ int p=0; if(x==‘/‘){for(int j=1;j<last;++j) if(a[j]!=j){ p=j; break;} } else for(int j=n;j>last;--j) if(a[j]!=j){ p=j; break;} if(!p) break; ans[i][p]=ans[i][last]=ans[i][a[p]]=x; a[last]=a[a[p]], a[a[p]]=a[p], last=p; swap(x,y); cerr<<last<<endl; } } printf("%d\n",n-(!!last)); for(int i=1; i<=n; ++i, puts("")) for(int j=1; j<=n; ++j) putchar(ans[i][j]?ans[i][j]:‘.‘);}
Codeforces round #516 (Div. 1, by Moscow team Olympus IAD) E