10333 - The Tower of ASCII
Moderator: Board moderators
10333 - The Tower of ASCII
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?
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;
}
}
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
10333
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;
}
}
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
10333 Wrong Anwers, But The Output is Correct
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]
Re: 10333 Wrong Anwers, But The Output is Correct
That is OK with the Output part of the problem, but their test output simply writes:yayas wrote:Code: Select all
printf("Tower : #%d\n",tm);
Code: Select all
Tower #n
-
- New poster
- Posts: 20
- Joined: Tue Sep 20, 2005 9:20 am
- Location: Daejeon, Korea
to yayas
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.
Thus, change your location of feof. (Don't use scanf to check that. )
That will be helpful.
The input data ends with tricky.
-
- Experienced poster
- Posts: 145
- Joined: Thu Aug 14, 2003 8:42 am
- Location: Mountain View, California
- Contact:
Re: 10333 - The Tower of ASCII
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?