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

Posted by Liuzhaoliang at 2014-10-05 04:41:10 on Problem 3505
#include<iostream>
#include<stdio.h>
#include<utility>
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++) 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;
}

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