120 - Stacks of Flapjacks
Moderator: Board moderators
120 Invalid reference memory help me!!!!
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;
}
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;
}
About Input data...
Actually, We don't need to consider about the same number inputs.
The problem defined like below.
Frankly, If I input the same numbers in my program, It's crazy..
The problem defined like below.
So I made a algorithm based on the problem. and I got A.C.... All pancakes in a stack have different diameters. ...
Frankly, If I input the same numbers in my program, It's crazy..

120 Problem
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!
Thanks!
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
Re: 120 Problem
Post your question to the forum about problems from the set I. This forum is about problems with java.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!
i dununderstand why this input for 120 will be this output
hi ppl,
below is the input and output.
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!
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
can someone pls further explain this to me? thx lots!
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".
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".
Best regards.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
-
- Experienced poster
- Posts: 101
- Joined: Wed May 04, 2005 4:33 pm
- Location: Tangerang, Banten, Indonesia
- Contact:
thanx tan_yui, but I got WA... can someone pointed out my mistake? here is my code:
I test with this input:
And the output is like this:
Code: Select all
removed after AC... thanks a lot tan_yui for your help
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
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
Last edited by Roby on Thu Dec 07, 2006 3:49 am, edited 1 time in total.
120, how can i get input from text file?
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.....
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.....
Last edited by Oronno on Mon Oct 06, 2008 11:58 am, edited 1 time in total.
I like programming but i am so lazy to do it...