--------
程序附在下面:
const str1=’What a poor boy!’;
var data:array[0..11,0..11] of longint;
n:longint;outt:array[0..11] of longint;key:array[0..11] of longint;
u:array[1..10] of boolean;
procedure print(k:longint);
var i:longint;
begin
case k of
-1:writeln(str1);
0:begin for i:=1 to n-1 do write(i,’ ’);write(n); end;
1:begin for i:=1 to n-1 do write(outt[i],’ ’);write(outt[n]); end;
end;
halt;
end;
procedure init;
var i,j,temp,t:longint;
begin
readln(n);fillchar(key,sizeof(key),0);fillchar(data,sizeof(data),0);
key[0]:=0;
for j:=1 to n do
begin
read(temp); if temp=0 then begin inc(key[0]);key[j]:=1; end;
data[j,0]:=temp;
for i:=1 to temp do begin read(t);data[j,i]:=t; end;
end;
if key[0]=0 then print(-1);
if key[0]=n then print(0);
end;
function serch(p:longint):boolean;
var i,j,k:longint;f:boolean;
begin
if key[p]=1 then begin serch:=true;
if not u[p] then begin
inc(outt[0]);outt[outt[0]]:=p;u[p]:=true;end;exit;end;
f:=true;
for i:=1 to data[p,0] do if not serch(data[p,i]) then begin f:=false;break;end;
if f then begin serch:=true;
if not u[p] then begin
inc(outt[0]);outt[outt[0]]:=p;u[p]:=true;key[p]:=1;
end;
end else serch:=false;
end;
procedure work;
begin
if serch(1) then print(1) else print(-1);
end;
begin
init;
work;
end.
------
第二题我感觉用广度搜索,和这一题比较类似:
马(宁波市23届程序设计复赛第3题)
Time Limit:3000MS Memory Limit:65536K
Total Submit:8 Accepted:4
Description 战神听说2008年中国将要举行奥林匹克运动会,心中觉得异常兴奋,他想让天马在天空中举行一场精彩的天马
队列变换表演。首先,战神安排n头高度不同的天马,排成一列。然后重复下面的变换:让中间的天马出列,然后
该匹天马可以排在队首,也可以排在队尾,这样称为一次变换,知道出现这一列天马按从低到高的顺序为止。那么
从初始状态到目标状态最少需要多少次变换?
Input 两行,第一行一个整数n,表示天马数。
第二行n个整数,分别表示n匹天马的高度,每两个数字中间一个空格。
Output 只有一行,一个整数,表示从初始状态到目标状态最少需要的变换次数。如果无论如何变换都不能得到从低到高的排列,
则输出“No Answer”
Sample Input 3179 173 175
Sample Output 2
Hint 100%的数据n只取3、5、7、9四个数字中的一个,且天马的高度为160至190之间的整数。
不知大牛看法如何?
------
第三,四题wish出得太难了,难道这就是传说中的提高组难度?如果是,我就完了!!!
That’s all ,thank you.
本来没想考几何的,不知哪天在某个地方看到提高组大纲里有几何,就出了(也不知道是不是看错了)
第四题比较简单,朴素的广搜就可以满分了
至于LZ提供的那题,数据范围很小,显然的搜索+剪枝
这次比赛第二题是稀疏 LCS 问题的优化。