Codeforces round #516 (Div. 1, by Moscow team Olympus IAD) E

Source: Internet
Author: User
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

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.