POJ 3505

题意:一个类似于硬磁盘的停车场,要从哪取车就让磁头转到哪然后让盘面旋转使得要取的车到磁头处,然后读取到信息回到出口处。。。然后给你取车顺序,问总花费时间。

题解:模拟吧。

View Code
 1 #include<cstdio>

 2 #include<cstring>

 3 #include<algorithm>

 4 using namespace std;

 5 int pos[55];

 6 struct data

 7 {

 8     int h,p;

 9 }po[55*55];

10 int main()

11 {

12     int T;

13     for(scanf("%d",&T);T;T--)

14     {

15         int h,w,n=0,tp,ans;

16         scanf("%d%d",&h,&w);

17         for(int i=0;i<h;i++)

18         {

19             pos[i]=0;

20             for(int j=0;j<w;j++)

21             {

22                 scanf("%d",&tp);

23                 if(tp!=-1)

24                 {

25                     n=max(tp,n);

26                     po[tp].h=i;

27                     po[tp].p=j;

28                 }

29             }

30         }

31         ans=0;

32         for(int i=1;i<=n;i++)

33         {

34             int hh=po[i].h,pp=po[i].p;

35             tp=abs(pos[hh]-pp);

36             tp=min(tp,w-tp);

37             ans+=hh*20+tp*5;

38             pos[hh]=pp;

39         }

40         printf("%d\n",ans);

41     }

42     return 0;

43 }

你可能感兴趣的:(poj)