UVA 10570 Meeting with aliens

Source: Internet
Author: User

#include <bits/stdc++.h>#defineREP (I,A,B) for (int i=a;i<=b;i++)#defineMS0 (a) memset (A,0,sizeof (a))using namespaceStd;typedefLong Longll;Const intmaxn=1000100;Const intinf=1<< in;intN,A[MAXN];intA1[MAXN],ID1[MAXN];intA2[MAXN],ID2[MAXN];intSolveintMint*a,int*ID) {    if(m==0)return 0; if(a[m]==m)returnSolve (M-1, A,id); intx=Id[m];    Swap (a[x],a[m]);    Swap (id[a[x]],id[a[m]]); return 1+solve (M-1, A,id);}intMain () {Freopen ("In.txt","R", stdin);  while(cin>>n,n) {MS0 (ID1);        MS0 (ID2); intst=1; REP (i,1, N) scanf ("%d",&A[i]); intans=INF; REP (St,1, N) {REP (i,st,n) a1[i-st+1]=A[i]; REP (i,1, st-1) a1[i+ (n-st+1)]=A[i]; intt=0;  for(inti=st;i>=1; i--) a2[++t]=A[i];  for(inti=n;i>st;i--) a2[++t]=A[i]; REP (i,1, N) id1[a1[i]]=i,id2[a2[i]]=i; //cout<<st<< "" <<ans<<endl;ans=min (Ans,min (Solve (N,A1,ID1), Solve (N,A2,ID2))); } cout<<ans<<Endl; }    return 0;}/** Why is it so different from the starting point of the direct pick 1? */
View Code

Beginning directly to 1 as the starting point has not been, and the starting point enumerated a bit but somehow over, although do not know why, but dare to dare to do is acmer the necessary qualities.

UVA 10570 Meeting with aliens

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.