|
|
вернуться в форум:(( I`m going to get MAD what`s wrong indeed? (+) Послано Pasha 19 мар 2003 14:18 Const Maxn = 130002; Var N, I, X, L, Ans : LongInt; P : Array[0..MaxN] of LongInt; Function GCD(X,Y:LongInt):LongInt; Begin If Y>X Then GCD:=GCD(Y,X) Else If Y=0 Then GCD:=X Else GCD:=GCD(Y, X MOD Y); end; begin Readln(N); For I := 1 To N Do Begin Read(X); P[X]:=I; End; X:=0; Ans:=0; For I := 1 To MaxN Do If P[I]>0 Then Begin Inc(X); L:=Abs(P[I]-X); If L>0 Then If Ans>0 Then Ans:=GCD(Ans,L) Else Ans:=L; End; If Ans=0 Then WriteLn(N-1) Else WriteLn(Ans-1); end. Re: :(( I`m going to get MAD what`s wrong indeed? (+) Послано hajime 19 мар 2003 14:39 > Const > Maxn = 130002; > Var > N, I, X, L, Ans : LongInt; > P : Array[0..MaxN] of LongInt; > > Function GCD(X,Y:LongInt):LongInt; > Begin > If Y>X Then > GCD:=GCD(Y,X) > Else > If Y=0 Then > GCD:=X > Else > GCD:=GCD(Y, X MOD Y); > end; > > begin > Readln(N); > For I := 1 To N Do > Begin > Read(X); > P[X]:=I; > End; > X:=0; > Ans:=0; > For I := 1 To MaxN Do > If P[I]>0 Then > Begin > Inc(X); > L:=Abs(P[I]-X); > If L>0 Then > If Ans>0 Then > Ans:=GCD(Ans,L) > Else > Ans:=L; > End; > If Ans=0 Then > WriteLn(N-1) > Else > WriteLn(Ans-1); > end. Sorting may be also in descending order Thanks a lot for your help Послано Pasha 19 мар 2003 16:20 My mail address is aidin_n7@hotmai.com I will glad to meet you more Best Aidin Re: Thanks a lot for your help Const Maxn = 1302; Var N, I, X, L, Ans,x2,l2,ans2: LongInt; P : Array[0..MaxN] of LongInt; Function GCD(X,Y:LongInt):LongInt; Begin If Y>X Then GCD:=GCD(Y,X) Else If Y=0 Then GCD:=X Else GCD:=GCD(Y, X MOD Y); end; begin Readln(N); For I := 1 To N Do Begin Read(X); P[X]:=I; End; X:=0; x2:=n; Ans:=0; ans2:=0; For I := 1 To MaxN Do If P[I]>0 Then Begin Inc(X); dec(x2); L:=Abs(P[I]-X); l2:=abs(p[i]-x2); If L>0 Then If Ans>0 Then Ans:=GCD(Ans,L) Else Ans:=L; If L2>0 Then If Ans2>0 Then Ans2:=GCD(Ans2,L2) Else Ans2:=L2; End; if ans=0 then ans:=n-1 else ans:=ans-1; if ans2=0 then ans2:=n-1 else ans2:=ans2-1; if ans>ans2 then writeln(ans) else writeln(ans2); end. sorry... i used some of your code.. |
|
|