10333 - The Tower of ASCII

All about problems in Volume 103. 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
Revenger
Experienced poster
Posts: 132
Joined: Sun Apr 14, 2002 12:27 pm
Location: Russia

10333 - The Tower of ASCII

Post by Revenger » Sun Jul 14, 2002 3:08 pm

I try to solve this problem on contest but get Time Limit. Then I change my program in proper way but get Wrong Answer. After contest I send the program and it get Accepted P.E. runnig 1.060 seconds. I just wonder how to get Accepted with time less that 0.100 seconds using Pascal. And I think that it is impossible; but then why ProblemSetter hadn't thougth about this?

famousun
New poster
Posts: 6
Joined: Sun Sep 29, 2002 5:04 pm

Post by famousun » Fri Oct 25, 2002 2:16 pm

I get WA when submit the following code , why , Can somobody tell me ?

are there any line break I don't know ?
that things do things with this problems?

///////////////////////////////////////////////////////////

#include<iostream.h>
void main()
{
int n , sum , a[500],i,k,tm=0, j,m,first,first1,g,wide,wid2;
while(!cin.eof())
{
sum = 0 ;
i = 0 ;
j = 0 ;
cin>>n ;
cout<<"Tower : #"<<++tm<<endl;
do{
sum += ++i ;
a[i-1] = i ;
}while(sum<n) ;
j = i - 1 ;
if(sum > n)
{
a[i-1] = n - sum + i ;

if(a[i-1]<a[i-2])
{
a[i-2] += a[i-1] ;
j = i - 2 ;
}

if(a[i-1] == a[i-2] )
{
a[i-2] *= 2 ;
j = i-2 ;
}
}
//cout<<j<<" "<<i<<" "<<a[i-2]<<endl ;
///////////////////////////////////////
for(m = 0; m < j; m++)
{
first = 2*(j - m) ;
first1 = first ;
wide = 4*m ;
wid2 = wide+4 ;
while(first--)
cout<<' ' ;
cout<<"#**" ;
while(wide--)
cout<<'.' ;
cout<<"**#" ;
cout<<endl ;
for(g = 0 ; g < a[m]-1; g++)
{
for(k=0;k<first1;k++)
cout<<' ' ;
cout<<'#' ;
for(k= wid2;k>0;k--)
cout<<'.';
cout<<'#'<<endl ;
}
}
///////////////////////////////////////
wide =4*(j) ;
wid2 = wide+2 ;
cout<<"#**" ;
while(wide--)
cout<<'.' ;
cout<<'#' ;
cout<<endl ;
for( g = 0 ; g < a[j]-1; g++)
{
cout<<'#' ;
for(k= wid2;k>0;k--)
cout<<'.';
cout<<'#'<<endl ;
}
cout<<endl;
}
}
Let's do things better

famousun
New poster
Posts: 6
Joined: Sun Sep 29, 2002 5:04 pm

10333

Post by famousun » Sun Nov 10, 2002 1:35 pm

My code get the right graphic like the example
but it get WA
I can examine it's why

can anybody tell me why?
my code is following :


#include<iostream.h>
void main()
{
int n , sum , a[500],i,k,tm=0, j,m,first,first1,g,wide,wid2;
while(!cin.eof())
{
sum = 0 ;
i = 0 ;
j = 0 ;
cin>>n ;
cout<<"Tower : #"<<++tm<<endl;
do{
sum += ++i ;
a[i-1] = i ;
}while(sum<n) ;
j = i - 1 ;
if(sum > n)
{
a[i-1] = n - sum + i ;

if(a[i-1]<a[i-2])
{
a[i-2] += a[i-1] ;
j = i - 2 ;
}

if(a[i-1] == a[i-2] )
{
a[i-2] *= 2 ;
j = i-2 ;
}
}
//cout<<j<<" "<<i<<" "<<a[i-2]<<endl ;
///////////////////////////////////////
for(m = 0; m < j; m++)
{
first = 2*(j - m) ;
first1 = first ;
wide = 4*m ;
wid2 = wide+4 ;
while(first--)
cout<<' ' ;
cout<<"#**" ;
while(wide--)
cout<<'.' ;
cout<<"**#" ;
cout<<endl ;
for(g = 0 ; g < a[m]-1; g++)
{
for(k=0;k<first1;k++)
cout<<' ' ;
cout<<'#' ;
for(k= wid2;k>0;k--)
cout<<'.';
cout<<'#'<<endl ;
}
}
///////////////////////////////////////
wide =4*(j) ;
wid2 = wide+2 ;
cout<<"#**" ;
while(wide--)
cout<<'.' ;
cout<<'#' ;
cout<<endl ;
for( g = 0 ; g < a[j]-1; g++)
{
cout<<'#' ;
for(k= wid2;k>0;k--)
cout<<'.';
cout<<'#'<<endl ;
}
cout<<endl;
}
}
Let's do things better

abc
New poster
Posts: 15
Joined: Sun Dec 15, 2002 2:51 pm

Post by abc » Tue Feb 25, 2003 12:07 am

post some input

yayas
New poster
Posts: 1
Joined: Thu Jun 12, 2003 12:09 pm
Location: Indonesia
Contact:

10333 Wrong Anwers, But The Output is Correct

Post by yayas » Thu Jun 12, 2003 12:25 pm

Code: Select all

[c]
#include<stdio.h>

void main() {
	int n , sum , a[500],i,k,tm=1, j,m,first,first1,g,wide,wid2;

	#ifndef ONLINE_JUDGE
		freopen("10333.in", "r", stdin);
		freopen("10333.out", "w", stdout);
	#endif
	while(scanf("%d",&n)==1)
	{
		sum = 0 ;
		i = 0 ;
		j = 0 ;
		printf("Tower : #%d\n",tm);
		tm++;
		do
		{
			sum += ++i ;
			a[i-1] = i ;
		} while(sum<n) ;

		j = i - 1 ;

		if(sum > n) {
			a[i-1] = n - sum + i ;

			if(a[i-1]<a[i-2]) {
				a[i-2] += a[i-1] ;
				j = i - 2 ;
			}

		  if(a[i-1] == a[i-2] ) {
				a[i-2] *= 2 ;
				j = i-2 ;
		  }
		}

		for(m = 0; m < j; m++) {
			first = 2*(j - m) ;
			first1 = first ;
			wide = 4*m ;
			wid2 = wide+4 ;

			while(first--)	printf(" ");
			printf("#**");
			while(wide--)  printf(".");
			printf("**#\n");
			for(g = 0 ; g < a[m]-1; g++) {
				for(k=0;k<first1;k++) printf(" ");
				printf("#");
				for(k= wid2;k>0;k--) printf(".");
				printf("#\n");
			}
		}

		wide =4*(j) ;
		wid2 = wide+2 ;
		printf("#**");

		while(wide--) printf(".");
		printf("#\n");

		for( g = 0 ; g < a[j]-1; g++) {
			printf("#");
			for(k= wid2;k>0;k--) printf(".");
			printf("#\n");
		}
		printf("\n");
		fflush(stdin);
	}
}

[/c]

abc
New poster
Posts: 15
Joined: Sun Dec 15, 2002 2:51 pm

Post by abc » Thu Sep 25, 2003 12:46 am

Can someone post something?

zoranh
New poster
Posts: 8
Joined: Wed Nov 26, 2003 7:23 pm

Re: 10333 Wrong Anwers, But The Output is Correct

Post by zoranh » Thu Feb 12, 2004 5:03 pm

yayas wrote:

Code: Select all

printf("Tower : #%d\n",tm);
That is OK with the Output part of the problem, but their test output simply writes:

Code: Select all

Tower #n
I have got AC after removing colon and space.

DongJoo Kim
New poster
Posts: 20
Joined: Tue Sep 20, 2005 9:20 am
Location: Daejeon, Korea

to yayas

Post by DongJoo Kim » Tue Sep 20, 2005 9:25 am

Change your location of feof. The output of your program is CORRECT. I checked your program and it was exactly same. I got AC.

Thus, change your location of feof. (Don't use scanf to check that. )

That will be helpful.

The input data ends with tricky.

DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

Re: 10333 - The Tower of ASCII

Post by DD » Sun Apr 03, 2011 3:03 am

Input:

Code: Select all

100
500

Code: Select all

Tower #1
                        #****#
                      #**....**#
                      #........#
                    #**........**#
                    #............#
                    #............#
                  #**............**#
                  #................#
                  #................#
                  #................#
                #**................**#
                #....................#
                #....................#
                #....................#
                #....................#
              #**....................**#
              #........................#
              #........................#
              #........................#
              #........................#
              #........................#
            #**........................**#
            #............................#
            #............................#
            #............................#
            #............................#
            #............................#
            #............................#
          #**............................**#
          #................................#
          #................................#
          #................................#
          #................................#
          #................................#
          #................................#
          #................................#
        #**................................**#
        #....................................#
        #....................................#
        #....................................#
        #....................................#
        #....................................#
        #....................................#
        #....................................#
        #....................................#
      #**....................................**#
      #........................................#
      #........................................#
      #........................................#
      #........................................#
      #........................................#
      #........................................#
      #........................................#
      #........................................#
      #........................................#
    #**........................................**#
    #............................................#
    #............................................#
    #............................................#
    #............................................#
    #............................................#
    #............................................#
    #............................................#
    #............................................#
    #............................................#
    #............................................#
  #**............................................**#
  #................................................#
  #................................................#
  #................................................#
  #................................................#
  #................................................#
  #................................................#
  #................................................#
  #................................................#
  #................................................#
  #................................................#
  #................................................#
#**................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#
#..................................................#

Tower #2
                                                            #****#
                                                          #**....**#
                                                          #........#
                                                        #**........**#
                                                        #............#
                                                        #............#
                                                      #**............**#
                                                      #................#
                                                      #................#
                                                      #................#
                                                    #**................**#
                                                    #....................#
                                                    #....................#
                                                    #....................#
                                                    #....................#
                                                  #**....................**#
                                                  #........................#
                                                  #........................#
                                                  #........................#
                                                  #........................#
                                                  #........................#
                                                #**........................**#
                                                #............................#
                                                #............................#
                                                #............................#
                                                #............................#
                                                #............................#
                                                #............................#
                                              #**............................**#
                                              #................................#
                                              #................................#
                                              #................................#
                                              #................................#
                                              #................................#
                                              #................................#
                                              #................................#
                                            #**................................**#
                                            #....................................#
                                            #....................................#
                                            #....................................#
                                            #....................................#
                                            #....................................#
                                            #....................................#
                                            #....................................#
                                            #....................................#
                                          #**....................................**#
                                          #........................................#
                                          #........................................#
                                          #........................................#
                                          #........................................#
                                          #........................................#
                                          #........................................#
                                          #........................................#
                                          #........................................#
                                          #........................................#
                                        #**........................................**#
                                        #............................................#
                                        #............................................#
                                        #............................................#
                                        #............................................#
                                        #............................................#
                                        #............................................#
                                        #............................................#
                                        #............................................#
                                        #............................................#
                                        #............................................#
                                      #**............................................**#
                                      #................................................#
                                      #................................................#
                                      #................................................#
                                      #................................................#
                                      #................................................#
                                      #................................................#
                                      #................................................#
                                      #................................................#
                                      #................................................#
                                      #................................................#
                                      #................................................#
                                    #**................................................**#
                                    #....................................................#
                                    #....................................................#
                                    #....................................................#
                                    #....................................................#
                                    #....................................................#
                                    #....................................................#
                                    #....................................................#
                                    #....................................................#
                                    #....................................................#
                                    #....................................................#
                                    #....................................................#
                                    #....................................................#
                                  #**....................................................**#
                                  #........................................................#
                                  #........................................................#
                                  #........................................................#
                                  #........................................................#
                                  #........................................................#
                                  #........................................................#
                                  #........................................................#
                                  #........................................................#
                                  #........................................................#
                                  #........................................................#
                                  #........................................................#
                                  #........................................................#
                                  #........................................................#
                                #**........................................................**#
                                #............................................................#
                                #............................................................#
                                #............................................................#
                                #............................................................#
                                #............................................................#
                                #............................................................#
                                #............................................................#
                                #............................................................#
                                #............................................................#
                                #............................................................#
                                #............................................................#
                                #............................................................#
                                #............................................................#
                                #............................................................#
                              #**............................................................**#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                              #................................................................#
                            #**................................................................**#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                            #....................................................................#
                          #**....................................................................**#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                          #........................................................................#
                        #**........................................................................**#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                        #............................................................................#
                      #**............................................................................**#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                      #................................................................................#
                    #**................................................................................**#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                    #....................................................................................#
                  #**....................................................................................**#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                  #........................................................................................#
                #**........................................................................................**#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
                #............................................................................................#
              #**............................................................................................**#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
              #................................................................................................#
            #**................................................................................................**#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
            #....................................................................................................#
          #**....................................................................................................**#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
          #........................................................................................................#
        #**........................................................................................................**#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
        #............................................................................................................#
      #**............................................................................................................**#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
      #................................................................................................................#
    #**................................................................................................................**#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
    #....................................................................................................................#
  #**....................................................................................................................**#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
  #........................................................................................................................#
#**........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#
#..........................................................................................................................#

Have you ever...
  • Wanted to work at best companies?
  • Struggled with interview problems that could be solved in 15 minutes?
  • Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.

Post Reply

Return to “Volume 103 (10300-10399)”