11364 - Parking

All about problems in Volume 113. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Esoo
New poster
Posts: 1
Joined: Fri Dec 25, 2009 5:52 pm

11364 - Parking

Post by Esoo » Fri Dec 25, 2009 6:07 pm

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. :)

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 11364 - Parking

Post by sazzadcsedu » Wed May 26, 2010 9:55 pm

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.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

tang_pow
New poster
Posts: 1
Joined: Sun Sep 12, 2010 9:52 pm

Re: 11364 - Parking

Post by tang_pow » Sun Sep 12, 2010 10:01 pm

An easier way, just output (max-min)*2

hehe...

LeoEyer
New poster
Posts: 1
Joined: Tue Sep 28, 2010 7:43 pm

Re: 11364 - Parking

Post by LeoEyer » Tue Sep 28, 2010 7:45 pm

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.

shopnobaj
New poster
Posts: 2
Joined: Mon Jun 27, 2011 5:23 pm

what wrong with my code?? uva 11364

Post by shopnobaj » Mon Jun 27, 2011 5:33 pm

//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;
}

shopnobaj
New poster
Posts: 2
Joined: Mon Jun 27, 2011 5:23 pm

what wrong with my code?? uva 11364

Post by shopnobaj » Mon Jun 27, 2011 5:44 pm

//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;
}

Sourov vai
New poster
Posts: 1
Joined: Tue Oct 29, 2013 11:50 am

Re: 11364 - Parking

Post by Sourov vai » Tue Oct 29, 2013 11:54 am

(max-min)*2 is the solution of parking.but how this distance is min distance?can any1 expalin me?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11364 - Parking

Post by brianfry713 » Tue Oct 29, 2013 9:38 pm

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.
Check input and AC output for thousands of problems on uDebug!

claus
New poster
Posts: 3
Joined: Sat Jan 02, 2016 2:44 am

Re: 11364 - Parking

Post by claus » Sun Jan 03, 2016 4:58 am

a
Last edited by claus on Sun Jan 03, 2016 5:45 am, edited 1 time in total.

claus
New poster
Posts: 3
Joined: Sat Jan 02, 2016 2:44 am

Re: 11364 - Parking

Post by claus » Sun Jan 03, 2016 5:44 am

claus wrote:Hi need help. WA. why ?


AC

input
1
7
29 0 99 45 36 78 25
}

Post Reply

Return to “Volume 113 (11300-11399)”