首页 > 其他 > 详细

模拟停车POJ(3505)

时间:2016-04-14 12:07:12      阅读:250      评论:0      收藏:0      [点我收藏+]

题目链接:http://poj.org/problem?id=3505

解题报告:

技术分享

技术分享
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

#define MAX 2600

struct Point{
    int x;
    int y;
}cars[MAX];

int mov[60];        ///每层停车场只有多少个停车位

int main()
{
    int  T;
    scanf("%d",&T);
    while(T--)
    {
        int h;  ///层数
        int l;  ///每层多少个位置

        scanf("%d%d",&h,&l);
        int sum=0;  ///总共有多少辆汽车

        for(int i=0;i<h;i++)
        {
            for(int j=0;j<l;j++)
            {
                int tmp;    ///车的编号
                scanf("%d",&tmp);
                if(tmp!=-1)
                {
                    cars[tmp].x=i;
                    cars[tmp].y=j;
                    sum++;
                }
            }
        }

        memset(mov,0,sizeof(mov));

        int ans=0;
        ///拿车
        for(int i=1;i<=sum;i++)
        {
            ans+=cars[i].x*20;
            int dis;
            dis=min(abs(cars[i].y-mov[cars[i].x]),l-abs(cars[i].y-mov[cars[i].x]));
            ans+=dis*5;
            mov[cars[i].x]=cars[i].y;   ///存下转盘当前位置
        }
        printf("%d\n",ans);
    }
    return 0;
}
View Code

 

模拟停车POJ(3505)

原文:http://www.cnblogs.com/TreeDream/p/5390392.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!