101 - The Blocks Problem

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

Moderator: Board moderators

teni_teni
New poster
Posts: 15
Joined: Sat Feb 05, 2005 8:04 am

Post by teni_teni »

Comment out these two lines, or you'll get 'compile error'.

Code: Select all

#include "stdafx.h"

 getchar();
There is no description about the maximum number of commands.

Code: Select all

 int n,onum,a[100],b[100],op[100],temp[30];
The size, 100, is too small. If not enough, runtime error will occur.


These, s1[4] and s2[4], cause strcmp to malfunction.

Code: Select all

 int i,k,j=1;char s1[4],s2[4];
So, you should replace 4 with 5 in order to hold '\0'.

Alejandro Sotelo Ar
New poster
Posts: 3
Joined: Tue Mar 15, 2005 6:37 am
Location: Bogot

Post by Alejandro Sotelo Ar »

This problem caused me an headache when I tried to solve it.
Which methods are available for me??

http://acm.uva.es/problemset/java.html :
"The current support for Java platform is provided by a standard gcj 2.95 installation"

Then, if you want to see compatibility, download:
http://public.planetmirror.com/pub/sour ... .95.tar.gz

And please see the following link: http://gcc.gnu.org/java/

Compile in your normal java compiler, and look for
compatibility as needed. This works fine for me.

For example, the class Vector included in gcj 2.95 only admits methods like elementAt(int) and setElementAt(Object, int); but this class doesn't accept methods like get(int) and set(int, Object)

gladiatorcn
New poster
Posts: 8
Joined: Wed Mar 30, 2005 9:46 am

101TE!!Help

Post by gladiatorcn »

My code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int stack[25][25];
int top[25],in_stack[25],index[25];
int n,i,j,p,q;

void popup(int x)
{
int k;
while(top[in_stack[x]]>index[x]+1)
{
k=stack[in_stack[x]][top[in_stack[x]]-1];
stack[k][top[k]++]=k;
in_stack[k]=k;
index[k]=top[k]-1;
top[in_stack[x]]--;
}
}

void print()
{
for(i=0;i<n;i++)
{
printf("%d: ",i);
for(j=0;j<top;j++)
printf("%d ",stack[j]);
printf("\n");
}
}

int main()
{
int k,temp,temp1;
char c1[4],c2[4];

scanf("%d",&n);
for(i=0;i<n;i++)
{
top=1;
in_stack=i;
index=0;
stack[0]=i;
}
scanf("%s",c1);
while(1)
{
if(strcmp(c1,"quit")==0)
break;
if(strcmp(c1,"move")==0)
{
scanf("%d %s %d",&p,c2,&q);
if(strcmp(c2,"onto")==0)
{
popup(q);
popup(p);
stack[in_stack[q]][top[in_stack[q]]++]=stack[in_stack[p]][--top[in_stack[p]]];
in_stack[p]=in_stack[q];
index[p]=top[in_stack[q]]-1;
}
else if(strcmp(c2,"over")==0)
{
popup(p);
stack[in_stack[q]][top[in_stack[q]]++]=p;
top[in_stack[p]]--;
in_stack[p]=in_stack[q];
index[p]=top[in_stack[p]]-1;
}
}
else if(strcmp(c1,"pile")==0)
{
scanf("%d %s %d",&p,c2,&q);
temp=top[in_stack[p]];
temp1=in_stack[p];
if(strcmp(c2,"onto")==0)
{
popup(q);
for(k=index[p];k<temp;k++)
{
stack[in_stack[q]][top[in_stack[q]]++]=stack[temp1][k];
top[temp1]--;
in_stack[stack[temp1][k]]=in_stack[q];
index[stack[temp1][k]]=top[in_stack[q]]-1;
}
}
else if(strcmp(c2,"over")==0)
{
for(k=index[p];k<temp;k++)
{
stack[in_stack[q]][top[in_stack[q]]++]=stack[temp1][k];
top[temp1]--;
in_stack[stack[temp1][k]]=in_stack[q];
index[stack[temp1][k]]=top[in_stack[q]]-1;
}
}
}
scanf("%s",c1);
}
print();
return 0;
}
Why is it Time Limit Exceeded? No such problem did I ever meet when I post it to other online judge system, like Peking University Online Judge.
Help me, please!

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

Re: 101TE!!Help

Post by tan_Yui »

gladiatorcn wrote:Why is it Time Limit Exceeded? No such problem did I ever meet when I post it to other online judge system, like Peking University Online Judge.
Help me, please!
TLE (Time Limit Exceeded) will be caused when your code did calc infinity or your algorithm was too much slow. I think that your algorithm isn't slow, so I propose you should check your code carefully again to avoid infinite calculation or wrong answer.
Your code outputs wrong answer in the case of sample input http://acm.uva.es/p/v1/101.html . And, in the case of input of 'mattty' http://online-judge.uva.es/board/viewto ... hlight=101, your code outputs same answer as the 'gits' output.
After above checking, you will get different judgement. :D

Best regards.

gladiatorcn
New poster
Posts: 8
Joined: Wed Mar 30, 2005 9:46 am

Post by gladiatorcn »

Thanx for ur sweet tips. I fixed all the problems, n still got TLE which bothers me a lot.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int stack[25][25];
int top[25],in_stack[25],index[25];
int n,i,j,p,q;

void popup(int x)
{
int k;
while(top[in_stack[x]]>index[x]+1)
{
k=stack[in_stack[x]][top[in_stack[x]]-1];
stack[k][top[k]++]=k;
in_stack[k]=k;
index[k]=top[k]-1;
top[in_stack[x]]--;
}
}

void print()
{
for(i=0;i<n;i++)
{
printf("%d: ",i);
for(j=0;j<top;j++)
printf("%d ",stack[j]);
printf("\n");
}
}

int main()
{
int k,temp,temp1;
char c1[4],c2[4];

scanf("%d",&n);
for(i=0;i<n;i++)
{
top=1;
in_stack=i;
index=0;
stack[0]=i;
}
while(1)
{
scanf("%s",c1);
if(strcmp(c1,"quit")==0)
break;
if(strcmp(c1,"move")==0)
{
scanf("%d %s %d",&p,c2,&q);
if(in_stack[p]==in_stack[q]) continue;
if(strcmp(c2,"onto")==0)
{
popup(q);
popup(p);
stack[in_stack[q]][top[in_stack[q]]++]=stack[in_stack[p]][--top[in_stack[p]]];
in_stack[p]=in_stack[q];
index[p]=top[in_stack[q]]-1;
}
else /*must be over*/
{
popup(p);
stack[in_stack[q]][top[in_stack[q]]++]=p;
top[in_stack[p]]--;
in_stack[p]=in_stack[q];
index[p]=top[in_stack[p]]-1;
}
}
else /* must be pile*/
{
scanf("%d %s %d",&p,c2,&q);
if(in_stack[p]==in_stack[q]) continue;
temp=top[in_stack[p]];
temp1=in_stack[p];
if(strcmp(c2,"onto")==0)
{
popup(q);
for(k=index[p];k<temp;k++)
{
stack[in_stack[q]][top[in_stack[q]]++]=stack[temp1][k];
in_stack[stack[temp1][k]]=in_stack[q];
index[stack[temp1][k]]=top[in_stack[q]]-1;
}
top[temp1]-=temp-index[p]-1;
}
else /*must be over*/
{
for(k=index[p];k<temp;k++)
{
stack[in_stack[q]][top[in_stack[q]]++]=stack[temp1][k];
in_stack[stack[temp1][k]]=in_stack[q];
index[stack[temp1][k]]=top[in_stack[q]]-1;
}
top[temp1]-=temp-index[p]-1;
}
}
}
print();
return 0;
}

nmatrice
New poster
Posts: 1
Joined: Sat Apr 02, 2005 9:35 pm

Pb 101 Runtime Error (SIGSEGV)

Post by nmatrice »

Hi !

I've got a Runtime Error (SIGSEGV) for this code but I don't understans why.
The program's references don't seem to out of bound.

Thanks.

Code: Select all

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define _MOVE      1
#define _PILE      2
#define _ONTO      3
#define _OVER      4
#define INTTBL      100
#define NBWORDS 100
#define Y               100

// identify the meaning of a word in the command
int iden(char *str){
    
 if(!strcmp(str, "move")) return _MOVE;
 else if(!strcmp(str, "pile")) return _PILE;   
 else if(!strcmp(str, "over")) return _OVER;
 else if(!strcmp(str, "onto")) return _ONTO;
 else return 0;
   
}

// give each word of le command
void strintbl(char tblc[NBWORDS][Y], char *str){
     
     int i=0,j=0,k=0;

     while(str[i]!='\0'){
                         
      while((str[i]!=' ') && (str[i]!='\0')){             
          
         tblc[j][k]=str[i];
         i++;
         k++;
                         
      }
      tblc[j][k]='\0';
      k=0;
      i++;
      j++;
     }
     
}

//initialize the string buffer
void inittbl(char tbl[NBWORDS][Y]){
     
     int i;
     for(i=0 ; i<NBWORDS; i++) tbl[i][0]='\0';     
     
}

//remove the spaces after the command stocked in the buffer
void adaptestr(char *str){
     
 int i=0;
 while(str[i]!='\0')
  i++;
 
 i--;
 
 while(str[i]==' '){
  str[i]='\0';     
  i--;
 }
     
}

//put in coord[x][y], the position of element a int the table
// x is the line and y the column
int searchnb(int tbl[INTTBL][INTTBL],int a, int coord[2]){
    
    
    int i=0, j=0;
    coord[0]=coord[1]=-1;
    
      for(i=0; i<INTTBL; i++){
               
               while(tbl[i][j]!=-1){
                 
                 if(tbl[i][j]==a){
                  
                   coord[0]=i;
                   coord[1]=j;
                                
                 }
                 j++;                   
                                 
               }
               j=0;        
      }     

}

// move function ... :)
void movenum(int tbl[INTTBL][INTTBL], int a, int b, int onto_or_over){
     
 int i=0,j=0;
 int coord[2];
 

 if(onto_or_over==-1){
  searchnb(tbl, a, coord);
  if(coord[0]!=-1 && coord[1]!=-1){
                  
   tbl[coord[0]][coord[1]] = -1;
   i=coord[1]+1;
   
   while(tbl[coord[0]][i]!=-1){tbl[coord[0]][i-1]=tbl[coord[0]][i]; i++;}

   tbl[coord[0]][i-1]=tbl[coord[0]][i];
   
   i=0;
   while(tbl[b][i]!=-1) i++;
   tbl[b][i] = a;                  
   
  } 
                      
 }
 else {
      
  searchnb(tbl,a, coord);
  if(coord[0]!=-1 && coord[1]!=-1){
   
   tbl[coord[0]][coord[1]] = -1;                
   
   i=coord[1]+1;
   
   while(tbl[coord[0]][i]!=-1){tbl[coord[0]][i-1]=tbl[coord[0]][i]; i++;}
   
   tbl[coord[0]][i-1]=tbl[coord[0]][i];
   
   i=0;
                     
  }
  
  searchnb(tbl,b,coord);
  
  if(coord[0]!=-1 && coord[1]!=-1){
  
   i=coord[1]+1;
   while(tbl[coord[0]][i]!=-1) i++;
   tbl[coord[0]][i]=a;
                  
  }        
      
 }    
     
}

// pile function ... :)
int pilenum(int tbl[INTTBL][INTTBL], int a , int b, int onto_or_over){
     
 int coorda[2];
 int coordb[2];
 int i=0;
 int j=0;
 
 searchnb(tbl,a, coorda);
 searchnb(tbl,b, coordb);
 
 if(coorda[0]==coordb[0]) return 0;
 
 i=coorda[1];
 
 if(onto_or_over==-1){
    
    while(tbl[b][j]!=-1)j++;
    while(tbl[coorda[0]][i]!=-1){tbl[b][j]=tbl[coorda[0]][i]; i++; j++; }                
                      
 }
 else{
 
    j=coordb[1]+1;
    while(tbl[coorda[0]][i]!=-1){tbl[coordb[0]][j]=tbl[coorda[0]][i]; i++; j++; }
 
 }
     
 i=coorda[1];
 while(tbl[coorda[0]][i]!=-1){tbl[coorda[0]][i]=-1; i++;}
 
 return 0;
}

// similar to atoi() function.
int ToInt(char *str){
    
 int p=1;
 int nb=0;
 int len=strlen(str);
 int i=0;
 i=len-1;
 
 while(i>=0){
   
   nb+= p*(str[i]-48);
   i--;
   p*=10;           
              
 } 
 return nb;
}

//execute the command
int exec(char tbl[NBWORDS][Y], int num[INTTBL][INTTBL],int i){

    int onto_or_over=-1;

    if((ToInt(&(tbl[1][0])) >= i) || (ToInt(&(tbl[3][0])) >= i) || (ToInt(&(tbl[1][0])) < 0) || (ToInt(&(tbl[3][0])) < 0)) return 0;
    
    if(iden(&(tbl[2][0])) == _OVER) onto_or_over=1;
                           
    if(iden(&(tbl[0][0]))== _MOVE) movenum(num, ToInt(&(tbl[1][0])), ToInt(&(tbl[3][0])), onto_or_over);
    else if(iden(&(tbl[0][0]))== _PILE) pilenum(num, ToInt(&(tbl[1][0])), ToInt(&(tbl[3][0])), onto_or_over);                    
    
    return 0;
}

//put -1 everywhere in the table tbl to marque the end of a line of numbers.
void inittabnum(int tbl[INTTBL][INTTBL]){
     
 int i,j;
 
 for(i=0; i<INTTBL; i++)
  for(j=0; j<INTTBL; j++)
   tbl[i][j]=-1;     
     
}

//equal to memset() function
void mem(char *str, char a, int b){
 
 int i;
 for(i=0; i<b; i++){
          
          str[i]=a;         
          
 }    
     
}

// last but not least. The main function :)
int main(){
    
 int a,i=30,j=0;
 int tbl[INTTBL][INTTBL];   
 char tblstr[NBWORDS][Y];
 char str[Y];
 
 inittabnum(tbl);
 
 while(i>25)
  scanf("%d", &i);
 
 for(a=0; a<i; a++)
  tbl[a][0]=a;
 
 mem(str,'\0',Y);

 gets(str);
 gets(str);
 while(strcmp(str, "quit")!=0){
    
  adaptestr(str);
  inittbl(tblstr);
  strintbl(tblstr, str);
  exec(tblstr, tbl,i);

  mem(str,'\0',Y);
  gets(str);                      
 }
    
 for(a=0; a<i; a++){
  
  
   printf("%d:", a);
   while(tbl[a][j]!=-1) {printf(" %d", tbl[a][j]); j++;}
   printf("\n");         
   j=0;       
 }
}

PS : I use Dev C++ 4.9.9.1 on Windows XP to compile the code.

roticv
Learning poster
Posts: 63
Joined: Sat Dec 11, 2004 9:28 am

Post by roticv »

Thanks alot. Your io helped me fixed quite a number of my bugs

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

Hello

Post by asif_rahman0 »

Hey Java code is not suitable for UVA submission.As far as I know UVA still using JDK 1.1.And Today JDK 1.5 with updates are available.And That's why many JAVA features are not supported at UVA.So,PLZ try to submitt all your codes either in C or in C++.

Hardi
New poster
Posts: 12
Joined: Fri Jun 10, 2005 2:44 pm
Location: Estonia, P

Post by Hardi »

I have a problem
Input:
5
move 1 onto 0
move 2 onto 0
move 3 onto 0
move 0 over 4

Is the output like that:

0:
1:
2:
3:
4: 0 ?

And does moving to initial position mean the same as move "the box that has to be moved" to "the value of the box" e.g:
0: 1 2
1:
2:
3:
4:

move 0 over 4:
0:
1:
2:
3:
4: 0

Gaolious
New poster
Posts: 28
Joined: Mon Nov 04, 2002 8:03 pm
Location: South Korea, Seoul
Contact:

result

Post by Gaolious »

the Result of each steps for follow input data

5
move 1 onto 0
move 2 onto 0
move 3 onto 0
move 0 over 4
5
move 1 onto 0
0: 0 1
1:
2: 2
3: 3
4: 4
move 2 onto 0
0: 0 2
1: 1
2:
3: 3
4: 4
move 3 onto 0
0: 0 3
1: 1
2: 2
3:
4: 4
move 0 over 4
0:
1: 1
2: 2
3: 3
4: 4 0


additional,

input
10
pile 6 onto 5
pile 5 over 2
pile 1 over 7
move 9 onto 6
move 6 over 6
pile 8 onto 9
move 0 over 3
pile 5 onto 2
move 8 onto 7
pile 6 onto 2
pile 3 onto 9
move 7 over 4
pile 0 onto 6
pile 0 over 3
move 0 over 1
pile 5 over 7
move 5 over 9
pile 7 over 5
move 5 over 7
move 4 onto 0
quit
output of each step
10
pile 6 onto 5
0: 0
1: 1
2: 2
3: 3
4: 4
5: 5 6
6:
7: 7
8: 8
9: 9
-------------------------------------
pile 5 over 2
0: 0
1: 1
2: 2 5 6
3: 3
4: 4
5:
6:
7: 7
8: 8
9: 9
-------------------------------------
pile 1 over 7
0: 0
1:
2: 2 5 6
3: 3
4: 4
5:
6:
7: 7 1
8: 8
9: 9
-------------------------------------
move 9 onto 6
0: 0
1:
2: 2 5 6 9
3: 3
4: 4
5:
6:
7: 7 1
8: 8
9:
-------------------------------------
move 6 over 6
pile 8 onto 9
0: 0
1:
2: 2 5 6 9 8
3: 3
4: 4
5:
6:
7: 7 1
8:
9:
-------------------------------------
move 0 over 3
0:
1:
2: 2 5 6 9 8
3: 3 0
4: 4
5:
6:
7: 7 1
8:
9:
-------------------------------------
pile 5 onto 2
move 8 onto 7
0:
1: 1
2: 2 5 6 9
3: 3 0
4: 4
5:
6:
7: 7 8
8:
9:
-------------------------------------
pile 6 onto 2
pile 3 onto 9
0:
1: 1
2: 2 5 6 9 3 0
3:
4: 4
5:
6:
7: 7 8
8:
9:
-------------------------------------
move 7 over 4
0:
1: 1
2: 2 5 6 9 3 0
3:
4: 4 7
5:
6:
7:
8: 8
9:
-------------------------------------
pile 0 onto 6
pile 0 over 3
move 0 over 1
0:
1: 1 0
2: 2 5 6 9 3
3:
4: 4 7
5:
6:
7:
8: 8
9:
-------------------------------------
pile 5 over 7
0:
1: 1 0
2: 2
3:
4: 4 7 5 6 9 3
5:
6:
7:
8: 8
9:
-------------------------------------
move 5 over 9
pile 7 over 5
move 5 over 7
move 4 onto 0
0:
1: 1 0 4
2: 2
3: 3
4:
5: 5
6: 6
7: 7
8: 8
9: 9
-------------------------------------

and

input
20
pile 6 onto 15
pile 15 over 12
pile 1 over 7
move 19 onto 6
move 6 over 16
pile 8 onto 9
move 10 over 3
pile 15 onto 2
move 18 onto 7
pile 16 onto 2
pile 13 onto 19
move 17 over 4
pile 10 onto 6
pile 0 over 13
move 10 over 1
pile 5 over 7
move 5 over 9
pile 17 over 15
move 5 over 7
move 4 onto 10
pile 8 over 18
move 4 onto 11
move 19 over 0
move 8 onto 12
move 6 over 19
pile 10 over 18
pile 1 onto 2
pile 12 over 16
pile 0 over 1
pile 9 over 19
quit
output
20
pile 6 onto 15
0: 0
1: 1
2: 2
3: 3
4: 4
5: 5
6:
7: 7
8: 8
9: 9
10: 10
11: 11
12: 12
13: 13
14: 14
15: 15 6
16: 16
17: 17
18: 18
19: 19
-------------------------------------
pile 15 over 12
0: 0
1: 1
2: 2
3: 3
4: 4
5: 5
6:
7: 7
8: 8
9: 9
10: 10
11: 11
12: 12 15 6
13: 13
14: 14
15:
16: 16
17: 17
18: 18
19: 19
-------------------------------------
pile 1 over 7
0: 0
1:
2: 2
3: 3
4: 4
5: 5
6:
7: 7 1
8: 8
9: 9
10: 10
11: 11
12: 12 15 6
13: 13
14: 14
15:
16: 16
17: 17
18: 18
19: 19
-------------------------------------
move 19 onto 6
0: 0
1:
2: 2
3: 3
4: 4
5: 5
6:
7: 7 1
8: 8
9: 9
10: 10
11: 11
12: 12 15 6 19
13: 13
14: 14
15:
16: 16
17: 17
18: 18
19:
-------------------------------------
move 6 over 16
0: 0
1:
2: 2
3: 3
4: 4
5: 5
6:
7: 7 1
8: 8
9: 9
10: 10
11: 11
12: 12 15
13: 13
14: 14
15:
16: 16 6
17: 17
18: 18
19: 19
-------------------------------------
pile 8 onto 9
0: 0
1:
2: 2
3: 3
4: 4
5: 5
6:
7: 7 1
8:
9: 9 8
10: 10
11: 11
12: 12 15
13: 13
14: 14
15:
16: 16 6
17: 17
18: 18
19: 19
-------------------------------------
move 10 over 3
0: 0
1:
2: 2
3: 3 10
4: 4
5: 5
6:
7: 7 1
8:
9: 9 8
10:
11: 11
12: 12 15
13: 13
14: 14
15:
16: 16 6
17: 17
18: 18
19: 19
-------------------------------------
pile 15 onto 2
0: 0
1:
2: 2 15
3: 3 10
4: 4
5: 5
6:
7: 7 1
8:
9: 9 8
10:
11: 11
12: 12
13: 13
14: 14
15:
16: 16 6
17: 17
18: 18
19: 19
-------------------------------------
move 18 onto 7
0: 0
1: 1
2: 2 15
3: 3 10
4: 4
5: 5
6:
7: 7 18
8:
9: 9 8
10:
11: 11
12: 12
13: 13
14: 14
15:
16: 16 6
17: 17
18:
19: 19
-------------------------------------
pile 16 onto 2
0: 0
1: 1
2: 2 16 6
3: 3 10
4: 4
5: 5
6:
7: 7 18
8:
9: 9 8
10:
11: 11
12: 12
13: 13
14: 14
15: 15
16:
17: 17
18:
19: 19
-------------------------------------
pile 13 onto 19
0: 0
1: 1
2: 2 16 6
3: 3 10
4: 4
5: 5
6:
7: 7 18
8:
9: 9 8
10:
11: 11
12: 12
13:
14: 14
15: 15
16:
17: 17
18:
19: 19 13
-------------------------------------
move 17 over 4
0: 0
1: 1
2: 2 16 6
3: 3 10
4: 4 17
5: 5
6:
7: 7 18
8:
9: 9 8
10:
11: 11
12: 12
13:
14: 14
15: 15
16:
17:
18:
19: 19 13
-------------------------------------
pile 10 onto 6
0: 0
1: 1
2: 2 16 6 10
3: 3
4: 4 17
5: 5
6:
7: 7 18
8:
9: 9 8
10:
11: 11
12: 12
13:
14: 14
15: 15
16:
17:
18:
19: 19 13
-------------------------------------
pile 0 over 13
0:
1: 1
2: 2 16 6 10
3: 3
4: 4 17
5: 5
6:
7: 7 18
8:
9: 9 8
10:
11: 11
12: 12
13:
14: 14
15: 15
16:
17:
18:
19: 19 13 0
-------------------------------------
move 10 over 1
0:
1: 1 10
2: 2 16 6
3: 3
4: 4 17
5: 5
6:
7: 7 18
8:
9: 9 8
10:
11: 11
12: 12
13:
14: 14
15: 15
16:
17:
18:
19: 19 13 0
-------------------------------------
pile 5 over 7
0:
1: 1 10
2: 2 16 6
3: 3
4: 4 17
5:
6:
7: 7 18 5
8:
9: 9 8
10:
11: 11
12: 12
13:
14: 14
15: 15
16:
17:
18:
19: 19 13 0
-------------------------------------
move 5 over 9
0:
1: 1 10
2: 2 16 6
3: 3
4: 4 17
5:
6:
7: 7 18
8:
9: 9 8 5
10:
11: 11
12: 12
13:
14: 14
15: 15
16:
17:
18:
19: 19 13 0
-------------------------------------
pile 17 over 15
0:
1: 1 10
2: 2 16 6
3: 3
4: 4
5:
6:
7: 7 18
8:
9: 9 8 5
10:
11: 11
12: 12
13:
14: 14
15: 15 17
16:
17:
18:
19: 19 13 0
-------------------------------------
move 5 over 7
0:
1: 1 10
2: 2 16 6
3: 3
4: 4
5:
6:
7: 7 18 5
8:
9: 9 8
10:
11: 11
12: 12
13:
14: 14
15: 15 17
16:
17:
18:
19: 19 13 0
-------------------------------------
move 4 onto 10
0:
1: 1 10 4
2: 2 16 6
3: 3
4:
5:
6:
7: 7 18 5
8:
9: 9 8
10:
11: 11
12: 12
13:
14: 14
15: 15 17
16:
17:
18:
19: 19 13 0
-------------------------------------
pile 8 over 18
0:
1: 1 10 4
2: 2 16 6
3: 3
4:
5:
6:
7: 7 18 5 8
8:
9: 9
10:
11: 11
12: 12
13:
14: 14
15: 15 17
16:
17:
18:
19: 19 13 0
-------------------------------------
move 4 onto 11
0:
1: 1 10
2: 2 16 6
3: 3
4:
5:
6:
7: 7 18 5 8
8:
9: 9
10:
11: 11 4
12: 12
13:
14: 14
15: 15 17
16:
17:
18:
19: 19 13 0
-------------------------------------
move 19 over 0
move 8 onto 12
0:
1: 1 10
2: 2 16 6
3: 3
4:
5:
6:
7: 7 18 5
8:
9: 9
10:
11: 11 4
12: 12 8
13:
14: 14
15: 15 17
16:
17:
18:
19: 19 13 0
-------------------------------------
move 6 over 19
0:
1: 1 10
2: 2 16
3: 3
4:
5:
6:
7: 7 18 5
8:
9: 9
10:
11: 11 4
12: 12 8
13:
14: 14
15: 15 17
16:
17:
18:
19: 19 13 0 6
-------------------------------------
pile 10 over 18
0:
1: 1
2: 2 16
3: 3
4:
5:
6:
7: 7 18 5 10
8:
9: 9
10:
11: 11 4
12: 12 8
13:
14: 14
15: 15 17
16:
17:
18:
19: 19 13 0 6
-------------------------------------
pile 1 onto 2
0:
1:
2: 2 1
3: 3
4:
5:
6:
7: 7 18 5 10
8:
9: 9
10:
11: 11 4
12: 12 8
13:
14: 14
15: 15 17
16: 16
17:
18:
19: 19 13 0 6
-------------------------------------
pile 12 over 16
0:
1:
2: 2 1
3: 3
4:
5:
6:
7: 7 18 5 10
8:
9: 9
10:
11: 11 4
12:
13:
14: 14
15: 15 17
16: 16 12 8
17:
18:
19: 19 13 0 6
-------------------------------------
pile 0 over 1
0:
1:
2: 2 1 0 6
3: 3
4:
5:
6:
7: 7 18 5 10
8:
9: 9
10:
11: 11 4
12:
13:
14: 14
15: 15 17
16: 16 12 8
17:
18:
19: 19 13
-------------------------------------
pile 9 over 19
0:
1:
2: 2 1 0 6
3: 3
4:
5:
6:
7: 7 18 5 10
8:
9:
10:
11: 11 4
12:
13:
14: 14
15: 15 17
16: 16 12 8
17:
18:
19: 19 13 9
-------------------------------------
and, not printed by some commands are ignored.

Hardi
New poster
Posts: 12
Joined: Fri Jun 10, 2005 2:44 pm
Location: Estonia, P

Post by Hardi »

Hy again.
Thank you for your test input.
My program was accepted in 0:00.20 sec and the amount of memory was 64 kbytes(I think, but still 64).

jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

how to fix P.E. in 101

Post by jaracz »

I keep all results in 2 dimentional-array
I also used "sentinels" in my array, i mean my array in sample input looks as follow:
0: 0 -1 -1 -1 -1 -1 -1 -1 -1 -1
1: 1 9 2 4 -1 -1 -1 -1 -1 -1
2: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
3: 3 -1 -1 -1 -1 -1 -1 -1 -1 -1
4: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
5: 5 8 7 6 -1 -1 -1 -1 -1 -1
6: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
7: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
8: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
9: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
There should be one line of output for each block position (i.e., n lines of output where n is the integer on the first line of input).
so...here's a part of my code responsible for printing

Code: Select all

for(int i = 0; i < n; i++)
{
    if(i)printf("\n");
    printf("%2d:",i);int j = 0;
    while(tab[i][j]>=0)
    printf(" %d",tab[i][j++]);
}
so my final answer is

Code: Select all

 0: 0
 1: 1 9 2 4
 2:
 3: 3
 4:
 5: 5 8 7 6
 6:
 7:
 8:
 9:
(I copied/pasted this output and normally there isn't any extra spaces after any row, so don't worry)

What is wrong with this??
keep it real!

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

You should not have spaces at the beginning of each line of output:

From output description:

The output should consist of the final state of the blocks world. Each original block position numbered i ( where n is the number of blocks) should appear followed immediately by a colon. If there is at least a block on it, the colon must be followed by one space, followed by a list of blocks that appear stacked in that position with each block number separated from other block numbers by a space. Don't put any trailing spaces on a line.

There should be one line of output for each block position (i.e., n lines of output where n is the integer on the first line of input).

Nowhere it states that the block position must be printed in a field of width 2. Perhaps the sample output is misleading here.

But in your code, you did this:

Code: Select all

printf("%2d:",i);
This should be:

Code: Select all

printf("%d:",i);
Hope this helps.

jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

Post by jaracz »

No, it didn't help

I change this "for" loop like you said, but still P.E.
any other suggestions?
keep it real!

jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

Post by jaracz »

sorry, your post was finaly correct, but incomplete

I got at last AC with this loop:

Code: Select all

for(int i = 0; i < n; i++)
{
    printf("%d:",i);int j = 0;
    while(tab[i][j]>=0)
    printf(" %d",tab[i][j++]);
    printf("\n");
}
but now I don't understand this text:
There should be one line of output for each block position (i.e., n lines of output where n is the integer on the first line of input).
I think I have now one more line of output, but anyway...thanks a lot!
keep it real!

Post Reply

Return to “Volume 1 (100-199)”