POJ 3505 && HDU 2341 Tower Parking(简单模拟)
来源:互联网 发布:室内装修效果设计软件 编辑:程序博客网 时间:2024/06/09 19:43
Description
塔式停车场,每一层都可以停车,当顾客需要取车的时候,升降机就会升降到停车的楼层,然后传输带就可以顺时针或者逆时针地进行转动,直到车的所在位置,然后升降机就降到出口处,完成取车的任务。不过过程需要注意升降机的升降位置就在上次的取车的位置开始,升降机每移动一成用时10,传送带每移动一个位置用时为5
Input
第一行为用例组数t,每组用例第一行为两个整数h和l分别表示停车场的楼层数和每一层的车位数,之后为以h*l矩阵表示停车场停车情况,-1表示该位置为空,否则表示该位置有车而该位置的数字表示取车顺序
Output
对于每组用例,输出取出全部车用时
Sample Input
2
1 5
-1 2 1 -1 3
3 6
-1 5 6 -1 -1 3
-1 -1 7 -1 2 9
-1 10 4 1 8 -1
Sample Output
25
320
Solution
简单模拟
Code
#include<iostream>#include<cstdio>#include<utility>#include<algorithm>using namespace std;typedef pair<int,int> pii;const int MOVE=10;//升降机移动一层用时 const int ROTATE=5;//传送带移动一个车位用时 pii loc[2510];//记录每辆车的位置 int car[50][50];int p[50];//记录传送带的位置 int h,l;int cnt;int main(){ int t; scanf("%d",&t); while(t--) { cnt=0; scanf("%d%d",&h,&l); for(int i=0;i<h;i++) for(int j=0;j<l;j++) { scanf("%d",&car[i][j]),cnt=max(cnt,car[i][j]);//统计需要取出的车的数量 if(car[i][j]!=-1)//记录车的位置 loc[car[i][j]].first=i,loc[car[i][j]].second=j; } for(int i=0;i<h;i++)//初始状态传送带位于第0个车位 p[i]=0; int tot=0;//初始化总用时 for(int c=1;c<=cnt;c++) { int i=loc[c].first; int j=loc[c].second; tot+=2*i*MOVE;//升降用时 tot+=ROTATE*min((p[i]-j+l)%l,(j-p[i]+l)%l);//传送带可顺时针也可逆时针,算出最短距离 p[i]=j;//记录传送带位置= } printf("%d\n",tot); } return 0;}
0 0
- POJ 3505 && HDU 2341 Tower Parking(简单模拟)
- poj 3505(Tower Parking)
- poj 3505 Tower Parking
- POJ 3505 Tower Parking
- poj 3505 Tower Parking
- poj-3505 Tower Parking
- POJ 3505 Tower Parking 没读懂
- POJ 3632 Optimal Parking(简单题)
- POJ 3632 && HDU 1673 Optimal Parking(水~)
- HDU 1673 Optimal Parking【简单题】
- 南邮 OJ 1557 Tower Parking
- hdu 3950 Parking Log(单点更新)
- HDU 4939 Stupid Tower Defense 简单DP
- HDU 1035 (简单模拟)
- POJ 3632 Optimal Parking
- poj 3632 Optimal Parking
- POJ 3632 Optimal Parking
- poj 3632 Optimal Parking
- 网络相关面试题1
- 韩信点兵算法
- Word如何转换成和PDF一样格式
- javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
- Sybase管理工具RazorSQL中文乱码问题
- POJ 3505 && HDU 2341 Tower Parking(简单模拟)
- 这个世界很残酷
- session,param,cookie使用分析
- nodeJs启动的时候:Error: Cannot find module '../build/Release/bson'的解决办法
- leetcode 日经贴,Cpp code -Delete Node in a Linked List
- 2012年5月SAT香港真题解析
- Eclipse中配置Tomcat服务器
- Hibernate 学习经验之谈-(一) 初始配置
- codeforces 558 C Amr and Chemistry