2072. 【2016.10.6NOIP普及模拟】Pond
(File IO): input:pond.in output:pond.out
时间限制: 1000 ms 空间限制: 262144 KB 具体限制 Goto ProblemSet
pond
这题就是等于纯打表,也可以说是循环打表。首先我们可以发现,开头和结尾时永远不会变的,XXX……OOO……__
例如 6 开头是XXXXXXOOOOOO__
结尾是__XOXOXOXOXOXO
所以过程就是每次做分两段为一组,也就是:
XXXXXXOOOOOO__
XXXXX__OOOOOXO
XXXXXOOOOO__XO
也就是 (1)找到XO和__,交换。
(2)从后往前找,找到第一个OO,再找到__,交换。即可。
但我们发现,XXX__OOOXOXOXO以后的都不相同,完全没有规律。所以简单地打表就行了。也就是
XXXOXOO__OXOXO
X__OXOOXXOXOXO
XOXOXO__XOXOXO
__XOXOXOXOXOXO
在后面删掉两个XO
XXXOXOO__O
X__OXOOXXO
XOXOXO__XO
__XOXOXOXO
最后没次循环N-4次,输出XO即可。
var
n,i,j,k:longint;
s:string;
s1,s11,s2,s22:char;
begin
assign(input,'pond.in');reset(input);
assign(output,'pond.out');rewrite(output);
readln(n);
for i:=1 to n do
s:=s+'X';
for i:=1 to n do
s:=s+'O';
s:=s+'__';
writeln(s);
for i:=1 to n do
begin
for j:=1 to n+1 do
if s[j]='O' then break;
if j>5 then
begin
for j:=1 to length(s) do
if s[j]='_' then
break;
s1:=s[j];
s11:=s[j+1];
for k:=1 to length(s) do
if s[k]='O' then
break;
s2:=s[k-1];
s22:=s[k];
s[j]:=s2;
s[j+1]:=s22;
s[k-1]:=s1;
s[k]:=s11;
writeln(s);
for j:=1 to length(s) do
if s[j]='_' then break;
s1:=s[j];
s11:=s[j+1];
for k:=j to length(s) do
if s[k]='X' then break;
s2:=s[k-1];
s22:=s[k-2];
s[j]:=s2;
s[j+1]:=s22;
s[k-1]:=s1;
s[k-2]:=s11;
writeln(s);
end
else
begin
write('XXX__OOOXO');
for j:=1 to n-3-1 do
write('XO');
writeln;
write('XXXOXOO__O');
for j:=1 to n-3-1 do
write('XO');
writeln;
write('X__OXOOXXO');
for j:=1 to n-3-1 do
write('XO');
writeln;
write('XOXOXO__XO');
for j:=1 to n-3-1 do
write('XO');
writeln;
write('__XOXOXOXO');
for j:=1 to n-3-1 do
write('XO');
writeln;
halt;
end;
end;
close(input);
close(output);
end.