Page 1 of 1

11364 - Parking

Posted: Fri Dec 25, 2009 6:07 pm
by Esoo
hi guys,

I want some help in this problem
http://uva.onlinejudge.org/index.php?op ... ID+7648769

I don't know what's the problem in my code but really i do my best but UVA still sending to me WA :cry: :x

This is my code:

Code: Select all

#include<iostream>
using namespace std;
int main()
{
	int T,n,x[100];
	int min ;
	int max ;
	int arr1[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	int arr2[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	cin >> T;
	if(T >= 1 && T <= 100)
	{
		for(int i=0;i<T;i++)
		{
			min =100000;
			max = -1;
			cin >> n;
			if(n >= 1 && n <= 20)
			{
				for(int j=0;j<n;j++)
				{
					cin >> x[j];
					if(x[j] >= 0 && x[j] <= 99)
					{
						continue;
					}
					else
						break;
				}
				for(int k =0;k<n;k++)
				{
					if(x[k] < min)
					{
						arr1[i] = min = x[k];
					}
					else if(x[k] > max)
					{
						arr2[i] = max = x[k];
					}
				}
			}
		}
		if(n>1)
		{
			for(int i=0;i<T;i++)
			{
				cout << (arr2[i] - arr1[i])*2 << endl;
			}
		}
		else if(n == 1)
			cout << "0" << endl;
	}
	return 0;
}
Thanks in advance for every one. :)

Re: 11364 - Parking

Posted: Wed May 26, 2010 9:55 pm
by sazzadcsedu
I dont know whats wrong with your code,because I didn't go through it.But One think i can say that your code is full of unnecessary things.This problem is basically very easy.Just do two things:-

1.Sort the input.
2.Then calculate sum of distance from 1st>2nd,2nd>3rd,3rd>4rth,and so on till last position,And then multiply it by 2.
3.you don't need to consider (2nd>1st and then 1st>2nd )and then (2nd>last && last>2nd) and like this.Because starting from any position(1st,2nd,3rd,......) will result same value.So starting from first position is enough to get the min distance.

Re: 11364 - Parking

Posted: Sun Sep 12, 2010 10:01 pm
by tang_pow
An easier way, just output (max-min)*2

hehe...

Re: 11364 - Parking

Posted: Tue Sep 28, 2010 7:45 pm
by LeoEyer
Hey can anyone tell me why am i getting WA?
all case tests that i tried were ok, and thre isn't a print line after output or blank space...

here is the code

Code: Select all

Program parking;

var
   k,t,i,j,n,aux:integer;
   v:array[0..25] of integer;









procedure ordena;
begin
     
     for i:=2 to n Do
       begin
            j:=i; aux:=v[i]; v[0]:=aux;
            while(v[j-1]> aux) do
            begin
                 v[j]:=v[j-1];
                 j:=j-1;
            end;
            v[j]:=aux;
       end;
end;


begin


   readln(t);
   for k:=1 to t do
   begin
          readln(n);
          for i:=1 to n do
             read(v[i]);
          ordena;
          aux:=2*(v[n]-v[1]);
          if (k=t) then
            write(aux)
          else
            writeln(aux);
   end;


end.

what wrong with my code?? uva 11364

Posted: Mon Jun 27, 2011 5:33 pm
by shopnobaj
//uva 11364
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
int num,slot_num,slot[100],i,sum,res,max,min;
scanf("%d",&num);

while(num--)
{
sum=0;
res=0;
max=-1;
min=0;
scanf("%d",&slot_num);
for(i=1;i<=slot_num;i++)
{
scanf("%d",&slot);
if(slot>max)
max = slot;
}
//printf("%d\n",max);
sort(slot,slot+i);
//for(j=1;j<=slot_num;j++)
//printf("%d ",slot[j]);
//printf("\n");
min = slot[1];
//printf("%d\n",min);
sum = (max-min);
res = (sum*2);
printf("%d\n",res);
}
return 0;
}

what wrong with my code?? uva 11364

Posted: Mon Jun 27, 2011 5:44 pm
by shopnobaj
//uva 11364
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
int num,slot_num,slot[100],i,sum,res,max,min;
scanf("%d",&num);

while(num--)
{
sum=0;
res=0;
max=-1;
min=0;
scanf("%d",&slot_num);
for(i=1;i<=slot_num;i++)
{
scanf("%d",&slot);
if(slot>max)
max = slot;
}
//printf("%d\n",max);
sort(slot,slot+i);
//for(j=1;j<=slot_num;j++)
//printf("%d ",slot[j]);
//printf("\n");
min = slot[1];
//printf("%d\n",min);
sum = (max-min);
res = (sum*2);
printf("%d\n",res);
}
return 0;
}

Re: 11364 - Parking

Posted: Tue Oct 29, 2013 11:54 am
by Sourov vai
(max-min)*2 is the solution of parking.but how this distance is min distance?can any1 expalin me?

Re: 11364 - Parking

Posted: Tue Oct 29, 2013 9:38 pm
by brianfry713
For example if you park at the end, you have to walk to the other end and back. If you park anywhere else it's the same total distance.

Re: 11364 - Parking

Posted: Sun Jan 03, 2016 4:58 am
by claus
a

Re: 11364 - Parking

Posted: Sun Jan 03, 2016 5:44 am
by claus
claus wrote:Hi need help. WA. why ?


AC

input
1
7
29 0 99 45 36 78 25
}