Codeforces Round #259 (Div. 2)

A. Little Pony and Crystal Mine 

题意:输出一个类似于十字形的东西

题解:直接打印即可。。。

代码:

 1 var n,i,j:longint;
 2 begin
 3   readln(n);
 4   for i:=1 to n>>1 do
 5    begin
 6      for j:=1 to (n-i<<1+1)>>1 do write('*');
 7      for j:=1 to i<<1-1 do write('D');
 8      for j:=1 to (n-i<<1+1)>>1 do write('*');
 9      writeln;
10    end;
11   for i:=1 to n do write('D');writeln;
12   for i:=n>>1 downto 1 do
13    begin
14      for j:=1 to (n-i<<1+1)>>1 do write('*');
15      for j:=1 to i<<1-1 do write('D');
16      for j:=1 to (n-i<<1+1)>>1 do write('*');
17      writeln;
18    end;
19 end.
20        
View Code

B. Little Pony and Sort by Shift

题意:给你一个数列,每次可以把最后一个数调到第一个数,求最少需要多少次能把这个数列变成单调增

题解:把原数列复制一遍接到后面,从头往前扫一遍用一个临时变量记录答案即可

代码:

 1 var n,i,cnt:longint;
 2     a:array[0..250000] of longint;
 3 begin
 4   readln(n);
 5   a[0]:=maxlongint;
 6   for i:=1 to n do read(a[i]);
 7   for i:=1 to n do a[n+i]:=a[i];
 8   cnt:=0;
 9   for i:=1 to n<<1 do
10    if a[i]>=a[i-1] then
11     begin
12       inc(cnt);
13       if cnt=n-1 then break;
14     end
15    else cnt:=0;
16   if cnt<>n-1 then writeln('-1')
17   else if i=n then writeln('0')
18   else writeln(n<<1-i);
19 end.     
View Code

CDE没看。。。或者看了不会。。。

原文地址:https://www.cnblogs.com/zyfzyf/p/3915929.html