488 - Triangle Wave

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

Moderator: Board moderators

ddddcccc30
New poster
Posts: 6
Joined: Sat Oct 06, 2007 4:30 am
Contact:

Post by ddddcccc30 »

Can anyone tell me why I get a Time limit exceeded? :cry:
Thanks.

Code: Select all

#include<iostream>
using namespace std;
int main( int argc, char * argv[] )
{ int use[10]={0,1,22,333,4444,55555,666666,7777777,88888888,999999999};
  long i , j , k ,l;
  long n , a , f ;
  cin  >>  n ;
  for(i=0;i<n;i++)  {
      cin  >>  a  >>  f;
      for(j=0;j<f;j++)  {
          for(k=1;k<=a;k++)   cout << use[k] << endl;
          for(k=a-1;k>=1;k--) cout << use[k] << endl;
          cout << endl;
        }
    }
  return 0;
}
turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

488, PE, PLES HELP

Post by turcse143 »

:( This my sample input output. I don't know whats the problem.
ples, help me correcting the output.
input:
2

3
2

4
3

output:
1
22
333
22
1

1
22
333
22
1

1
22
333
4444
333
22
1

1
22
333
4444
333
22
1

1
22
333
4444
333
22
1
Press any key to continue
CMG
New poster
Posts: 37
Joined: Sat Dec 08, 2007 5:01 am
Location: ...

Post by CMG »

That output looks good to me. The only thing tricky about this problem is making sure not to print an empty line at for the very last triangle wave, and being able to print all of the triangle waves fast enough.
jackpigman
New poster
Posts: 8
Joined: Fri Jan 04, 2008 5:57 pm

Post by jackpigman »

I'm getting lots of WAs. Can somebody help me?? Here's my code

Code: Select all

#include <stdio.h> 
int main() 
{ 
    int a,b,c,d,e,f,g,i; 
    while(scanf("%d",&a)==1) 
    { 
        int h[a*2]; 
        printf("\n"); 
        for(i=0;i<=a*2-2;i=i+2) 
        { 
            scanf("%d %d",&h[i],&h[i+1]); 
            if(i!=a*2-2) printf("\n"); 
        } 
        c=0;d=1; 
        for(b=1;b<=a;b++) 
        { 
            for(e=1;e<=h[d];e++) 
            { 
                for(f=1;f<=h[c];f++) 
                { 
                    g=0; 
                    while(g!=f) 
                    {printf("%d",f);g++;} 
                    printf("\n"); 
                } 
                for(f=h[c]-1;f>=1;f--) 
                { 
                    g=0; 
                    while(g!=f) 
                    {printf("%d",f);g++;} 
                    printf("\n"); 
                } 
                if(e!=h[d] || b!=a) printf("\n"); 
            } 
            c=c+2;d=d+2; 
        } 
    } 
} 
Thanks for your help :D !!
helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo »

You're printing an extra blank line at the first line.. :-)



PS. Remove your code after AC
jackpigman
New poster
Posts: 8
Joined: Fri Jan 04, 2008 5:57 pm

Post by jackpigman »

helloneo wrote:You're printing an extra blank line at the first line.. :-)


But the question says "This line is followed by a blank line, and there is also a blank line between two consecutive inputs", so shouldn't there be a blank line after the first line :o ??
I did try to remove it but still got a WA...Anyway, thanks for your help :D !
animenologist
New poster
Posts: 7
Joined: Tue Jan 22, 2008 5:55 am

Post by animenologist »

Don't know where I'm doing wrong. I've tried several things and changed it around a lot, but I keep getting a wrong answer. I checked my output with every thread containing 488, but each and every time, I can't figure out what is going on.

Code: Select all

CUT 
edit: nvm I got it.
AcmNightivy
New poster
Posts: 36
Joined: Tue Dec 04, 2007 10:20 am

Post by AcmNightivy »

Why i got TLE..It's really strange..And i changed using scanf() and printf (),it becamed WA..And i want to know what is blue flag,and what is the meaning of so called multiple input.It isn't like the input about this problem?Thanks in advance~

Code: Select all

#include <iostream.h>

int main ()
{
	int i, j, k;
	int caseNum;
	int a, f;
	char num[10][10] = {"", "1", "22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999"};

	cin>>caseNum;

	for (i = 0; i < caseNum; i++)
	{
		cin>>a>>f;

		for (j = 0; j < f; j++)
		{
			for (k = 1; k <= a; k++)
			{
				cout<<num[k]<<endl;
			}
			k = k - 2;
			for (; k >= 1; k--)
			{
				cout<<num[k]<<endl;
			}
			cout<<endl;
		}	
	}
	return 0;
}
fR0D
New poster
Posts: 29
Joined: Mon Feb 11, 2008 5:59 am
Contact:

why is my program TLE???

Post by fR0D »

why is my program TLE???

Code: Select all

code deleted after AC
Last edited by fR0D on Fri Feb 22, 2008 3:02 pm, edited 1 time in total.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

cout and cin are very slow.
Try to use putchar/printf/scanf instead.

Or as an option, call std::ios::sync_with_stdio(false); at the start of your program. This should make it a little faster.
fR0D
New poster
Posts: 29
Joined: Mon Feb 11, 2008 5:59 am
Contact:

Post by fR0D »

thnx vry much it helped nd i got AC.
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Crazzzzzzzzzzzzy WA...488

Post by Obaida »

why this will get WA.....

Code: Select all

#include <stdio.h> 
int main() 
{ 
	int a,b,i,j,k,n,s; 
	while(scanf("%d",&n)==1)
	{
		printf("\n");
		s=0;
		while(s!=n) 
		{ 
			scanf("%d %d",&a,&b); 
			printf("\n"); 
			for(k=0;k<b;k++) 
			{ 
				for(i=0;i<a;i++) 
				{ 
					for(j=0;j<i+1;j++) 
						printf("%d",i+1); 
					printf("\n");
				} 
				for(i=a-2;i>=0;i--) 
				{
					for(j=0;j<i+1;j++) 
						printf("%d",i+1);
					printf("\n");
				} 
				printf("\n"); 
			}
			s++;
		}
	}
return 0; 
}
some one please help me............. please....
try_try_try_try_&&&_try@try.com
This may be the address of success.
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Stupid problem........

Post by Obaida »

Thank you......488.... it give me at least 20 or more wA.... some one please help me..........please.........

Code: Select all

Removed
Last edited by Obaida on Sat Mar 01, 2008 11:07 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: Stupid problem........

Post by helloneo »

Obaida wrote:Thank you......488.... it give me at least 20 or more wA.... some one please help me..........please.........
You are printing an extra '\n' at the first line of the output.. :-)


PS. Remove you code after AC.. :-)
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

stupid......problem.

Post by Obaida »

Now look at my output.... I thik thats good.... but still WA

Code: Select all

2\n
\n
3\n
2\n
1\n
22\n
333\n
22\n
1\n
\n
1\n
22\n
333\n
22\n
1\n
\n
3\n
2\n
1\n
22\n
333\n
22\n
1\n
\n
1\n
22\n
333\n
22\n
1\n

try_try_try_try_&&&_try@try.com
This may be the address of success.
Post Reply

Return to “Volume 4 (400-499)”