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 }轉載于:https://www.cnblogs.com/tmeteorj/archive/2012/09/21/2697131.html
總結
- 上一篇: nodejs 加密压缩文件,解密解压文件
- 下一篇: 清明节全网灰色主题实现原理