Page 6 of 8

Posted: Fri Mar 03, 2006 4:40 pm
by devious
what?!

120 Invalid reference memory help me!!!!

Posted: Thu Aug 17, 2006 8:57 pm
by hoooh
Help me

why?


# include <stdio.h>
# include <stdlib.h>


int comparar(const void *a,const void *b)
{
if(*(int *)a<*(int *)b)
return(1);

if(*(int *)a>*(int *)b)
return(-1);

return(0);
}

void Voltear(int pank[100],int pos,int cant)
{
int i;
int aux;
int t;

printf("%d ",(cant-pos)%cant);

t=pos/2+pos%2;

for(i=0;i<t;i++)
{
aux=pank;
pank=pank[pos-i];
pank[pos-i]=aux;
}
}

int Posicion(int pank[100],int num)
{
int i=0;

while(true)
{
if(pank==num)
return i;
i++;
}
}




void Procesar(int pank[100],int copPank[100],int cant)
{
int i;
int pos;
qsort(copPank,cant,sizeof(copPank[0]),comparar);

for(i=0;i<cant;i++)
{
pos=Posicion(pank,copPank);

if(pos==0)
{
Voltear(pank,cant-i-1,cant);
continue;
}

if (pos+i==cant-1)
continue;

Voltear(pank,pos,cant);
Voltear(pank,cant-i-1,cant);
}
}


int main()
{
char c;
char f;
int pank[100];
int copPank[100];
int i=0;

while(scanf("%d%c",&f,&c)!=EOF)
{
pank=f;
copPank=f;

i++;
if(c=='\n')
{
Procesar(pank,copPank,i);
printf("\n");
i=0;
}
}

return 0;

}

Posted: Thu Aug 17, 2006 9:10 pm
by nev4
using pointers and arrays(which are pointers too) causes this(if u try to access memory u shouldn't to).

About Input data...

Posted: Wed Aug 30, 2006 12:38 pm
by mosaick2
Actually, We don't need to consider about the same number inputs.
The problem defined like below.
... All pancakes in a stack have different diameters. ...
So I made a algorithm based on the problem. and I got A.C.

Frankly, If I input the same numbers in my program, It's crazy.. :o

120 Problem

Posted: Tue Sep 12, 2006 12:52 am
by Disatoba
HI I got WA in problem 120, i dont know why? would someone help me with any test cases or ideas for to get AC?
Thanks!

120 WA

Posted: Tue Sep 12, 2006 12:55 am
by Disatoba
HI I got WA in problem 120, i dont know why? would someone help me with any test cases or ideas for to get AC?
Thanks!

Re: 120 Problem

Posted: Tue Sep 12, 2006 11:10 pm
by Martin Macko
Disatoba wrote:HI I got WA in problem 120, i dont know why? would someone help me with any test cases or ideas for to get AC?
Thanks!
Post your question to the forum about problems from the set I. This forum is about problems with java.

i dununderstand why this input for 120 will be this output

Posted: Sun Oct 01, 2006 7:38 pm
by douzi0108
hi ppl,

below is the input and output.

Code: Select all

Input:

1 2 3 1 2
2 3 1
2 3 4 1 8 9 6 7
2 3 4 1 8 9 6 7 0
5 1 3 6 4 1 9 2 0 18 29

Output:
1 1 2 2 3
3 1 3 0
1 2 3
2 1 0
1 2 3 4 6 7 8 9
6 3 1 3 0
0 1 2 3 4 6 7 8 9
7 4 2 4 2 1 0
0 1 1 2 3 4 5 6 9 18 29
9 5 9 6 8 3 8 6 9 0
for the first 5 input, i can see that once all the big pancakes has been to the top, we can start flipping them to the bottom. but when i apply this to the last input, i dun understand why the biggest pancake is not always the first to be chosen.

can someone pls further explain this to me? thx lots!

Posted: Wed Dec 06, 2006 7:21 am
by Roby
If I simulate like these:
8 4 6 7 5 2 -> 6
2 5 7 6 4 8 -> 3
7 5 2 6 4 8 -> 5
4 6 2 5 7 8 -> 2
6 4 2 5 7 8 -> 4
5 2 4 6 7 8 -> 3
4 2 5 6 7 8 -> 2
2 4 5 6 7 8 -> 0

5 1 2 3 4 -> 5
4 3 2 1 5 -> 4
1 2 3 4 5 -> 0
Does the algorithm correct? I just want to clarify if my approach is correct.

Posted: Wed Dec 06, 2006 9:09 am
by tan_Yui
I think your approach is correct.
But the flips' ID is a bit funny.
(.... you may have done it on purpose to explain plainly for us) :)
Convert to "ID = (Number of pancakes) + 1 - ID".
Roby wrote: 8 4 6 7 5 2 -> 1
2 5 7 6 4 8 -> 4
7 5 2 6 4 8 -> 2
4 6 2 5 7 8 -> 5
6 4 2 5 7 8 -> 3
5 2 4 6 7 8 -> 4
4 2 5 6 7 8 -> 5
2 4 5 6 7 8 -> 0

5 1 2 3 4 -> 1
4 3 2 1 5 -> 2
1 2 3 4 5 -> 0
Best regards.

Posted: Wed Dec 06, 2006 10:17 am
by Roby
thanx tan_yui, but I got WA... can someone pointed out my mistake? here is my code:

Code: Select all

removed after AC... thanks a lot tan_yui for your help
I test with this input:

Code: Select all

8 4 6 7 5 2
1 2 3 4 5
5 4 3 2 1
5 1 2 3 4
4 4 1
5 5 5
And the output is like this:

Code: Select all

8 4 6 7 5 2
6 3 5 2 4 3 2 0
1 2 3 4 5
0
5 4 3 2 1
5 0
5 1 2 3 4
5 4 0
4 4 1
3 0
5 5 5
0

Posted: Wed Dec 06, 2006 11:49 pm
by tan_Yui
Roby wrote:8 4 6 7 5 2
1 2 3 4 5
5 4 3 2 1
5 1 2 3 4
My output is :
8 4 6 7 5 2
1 4 2 5 3 4 5 0
1 2 3 4 5
0
5 4 3 2 1
1 0
5 1 2 3 4
1 2 0
Please check my previous post again.
And, we don't need to consider about the last 2 cases, as mosaick2 says.

Best regards.

Posted: Thu Dec 07, 2006 3:38 am
by Roby
What a silly mistake :oops: I changed the code so the ID will be like this:
ID = (number of pancakes) - ID
And I got AC..

Thanx tan_yui for your help... :P

120, how can i get input from text file?

Posted: Sun Feb 04, 2007 6:47 am
by Oronno
I have solved this problem, but it works only for 1 line input.
I can't understand how can i get multiple input for this progeamme.
Anyone can help me please?
Please dont say me to get the input as a string, because i think, it will not the actual solve of this problem.
please help me.....

Posted: Sun Feb 04, 2007 7:00 am
by helloneo
Why you don't think getting input as a string is not the solution..?
gets() + strtok() works fine..
Also, you can use scanf() + getchar() (only when there is no traling space in the input)

By the way, you don't need to use big red letters.. Everybody can read normal letters.. :)