Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:这样动规

Posted by lydliyudong at 2011-04-14 13:40:30 on Problem 1920 and last updated at 2011-04-14 13:42:11
In Reply To:同学们,这个题目怎么做? Posted by:cathy at 2005-09-05 19:09:09
1.首先肯定要移到最大的所在的柱子上。
2.然后倒着扫一遍确定每个盘子当前需要移动到的目标柱。
3.最后正着动规算出答案完事。
关于第二步:
例如说,最大的盘子在3号柱,倒数第二大的在2号柱,那么倒数第二大的目标柱就是3号,那么之前一定需要把倒数第三大及以前的盘子都移到1号(只有这样倒数第二大的才能在2、3之间移动),所以倒数第三大的目标柱就是1号……依此类推,求出目标柱。
最后正着动规一遍,若目标柱与当前所在柱相同,不累加答案,若不同则f[i]:=f[i-1]+1+han3[i-1];
han3是预处理出的,一般的普通3塔游戏移动i个盘子的步数。
var
 a:array[1..3]of longint;
 b,c,f:array[0..100000]of longint;
 n,i,j,k,ans:longint;

procedure scanf;
 begin
  read(n);
  for i:=1 to n do
   f[i]:=(2*f[i-1]+1)mod 1000000;
  for i:=1 to 3 do read(a[i]);
  for i:=1 to 3 do
   for j:=1 to a[i] do
    begin read(k); b[k]:=i; end;
 end;

begin
 scanf;
 c[n]:=b[n];
 writeln(b[n]);
 for i:=n-1 downto 1 do
  if b[i+1]=c[i+1] then c[i]:=b[i+1]
  else c[i]:=6-b[i+1]-c[i+1];
 for i:=1 to n do
  if b[i]=c[i] then continue
  else ans:=(ans+1+f[i-1])mod 1000000;
 writeln(ans);
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator