488 - Triangle Wave
Moderator: Board moderators
Re: 488 TLE
I am sending you a code by PM you better check it.
And trace the method.
And trace the method.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 488 TLE
Actually mine is similar to yours and I submit my code again, still time limit exceededObaida wrote:I am sending you a code by PM you better check it.
And trace the method.
Is it related to repeatedly calling the function in my program?
Code: Select all
Removed after AC
Last edited by hahahaken on Fri May 30, 2008 10:34 am, edited 1 time in total.
Re: 488 TLE
Try it removing the function. Hope it will work.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 488 TLE
I have already removed the function, TLE AGAIN, NO!!!Obaida wrote:Try it removing the function. Hope it will work.
Pls take a look at my code, I think there should be something wrong.
Code: Select all
Removed after AC
Last edited by hahahaken on Fri May 30, 2008 10:35 am, edited 1 time in total.
Re: 488 TLE
Those cin and cout are slow function.
Remove them and use printf and scanf.
Remove them and use printf and scanf.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 488 TLE
The version you sent me also uses cin and cout, it's a AC, right?Obaida wrote:Those cin and cout are slow function.
Remove them and use printf and scanf.
Mine is not just only exceeded for a few seconds, but at least 5 - 10s, coz I keep refreshing firefox and the status keep "running" until TLE appears.
Then, the problem is that why you use cin and cout and you got correct answer but mine got TLE?
Re: 488 TLE
You should check it out, and i think it's possible for you.
So why it's me?
So why it's me?
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 488 TLE
In this problem, you can replace "endl" with "\n" and get reasonable runtime. "endl" push a character "\n" into I/O buffer and flush the buffer immediately. Frequent flushing will take a lot of time, especially with massive I/O data.Obaida wrote:Those cin and cout are slow function.
Remove them and use printf and scanf.
Although "endl" is somehow slower than single "\n", "endl" is not bad at all. The advantage of "endl" is that we can ensure the I/O data printing on the screen, line by line. Even though the program crashed, we still can see all messages generated by the program before the crashing. The advantage of "endl" is helpful when debugging.
BTW, cin and cout can be faster if we set up this:
Code: Select all
cin.sync_with_stdio(false);
cout.sync_with_stdio(false);
Re: 488 TLE
Finally got AC, thanks
But I want to know why the following can make my program run faster:
1. What's the difference between "endl" and "\n"?
2. What's the difference between "cin and cout" and "scanf and printf"?
3. Why "cin.sync_with_stdio(false);" and "cout.sync_with_stdio(false);" can make my program run faster?
But I want to know why the following can make my program run faster:
1. What's the difference between "endl" and "\n"?
2. What's the difference between "cin and cout" and "scanf and printf"?
3. Why "cin.sync_with_stdio(false);" and "cout.sync_with_stdio(false);" can make my program run faster?
Re: 488 TLE
They are good questions. But I cannot explain them within few words (because I am inarticulate in English). It needs deeper views about the hardware architecture and about C/C++ languages. You may google or ask others for the details.hahahaken wrote:Finally got AC, thanks
But I want to know why the following can make my program run faster:
1. What's the difference between "endl" and "\n"?
2. What's the difference between "cin and cout" and "scanf and printf"?
3. Why "cin.sync_with_stdio(false);" and "cout.sync_with_stdio(false);" can make my program run faster?
-
- Experienced poster
- Posts: 162
- Joined: Thu Jul 13, 2006 7:07 am
- Location: Campus Area. Dhaka.Bangladesh
- Contact:
Re: Crazzzzzzzzzzzzy WA...488
There would be only one test case.
You need not to handle it upto EOF.
just change
** You must avoid printing newline at the last of output.
You need not to handle it upto EOF.
just change
** You must avoid printing newline at the last of output.
Code: Select all
while(scanf("%d",&n) ==1){
-------
-------
}
to
scanf("%d",&n);
------
------
http://www.newton.0fees.net is enough!
Re: WA 488
Why I get wrong anser with my code what is the solution?
Code: Select all
[b]# include <stdio.h>
int main()
{
int cases,i,height,frequency,j;
char line;
while(scanf("%d",&cases)==1)
{
for(i=0;i<cases;i++)
{
scanf("%d",&height);
scanf("%d",&frequency);
for(int l=0;l<frequency;l++)
{
if(l!=0)
printf("\n\n");
for(j=1;j<=height;j++)
{
for(int k=0;k<j;k++)
printf("%d",j);
printf("\n");
}
for(j=height-1;j>=1;j--)
{
if(j!=height-1)
printf("\n");
for(int k=0;k<j;k++)
printf("%d",j);
}
}
}
}
return 0;
}[/b]
R|_|\/|\/|/-\|\|
Re: WA 488
any1 can help why I get WA?
Code: Select all
# include <stdio.h>
int main()
{
int cases,i,height,frequency,j;
scanf("%d",&cases);
for(i=0;i<cases;i++)
{
scanf("%d",&height);
scanf("%d",&frequency);
for(int l=0;l<frequency;l++)
{
if(l!=0)
printf("\n");
printf("\n");
for(j=1;j<=height;j++)
{
for(int k=0;k<j;k++)
printf("%d",j);
printf("\n");
}
for(j=height-1;j>=1;j--)
{
if(j!=height-1)
printf("\n");
for(int k=0;k<j;k++)
printf("%d",j);
}
}
}
return 0;
}
R|_|\/|\/|/-\|\|
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Re: WA 488
You should not print a blank line at the very beginning.
Why WA in 488
What is the problem with code any problem with my code? Is the way I taking input is right? Please help...
Code: Select all
# include <stdio.h>
int main()
{
int cases,i,height,frequency,j;
scanf("%d",&cases);
for(i=0;i<cases;i++)
{
scanf("%d",&height);
scanf("%d",&frequency);
for(int l=0;l<frequency;l++)
{
if(l!=0)
printf("\n");
for(j=1;j<=height;j++)
{
for(int k=0;k<j;k++)
printf("%d",j);
printf("\n");
}
for(j=height-1;j>=1;j--)
{
if(j!=height-1)
printf("\n");
for(int k=0;k<j;k++)
printf("%d",j);
}
printf("\n");
}
}
return 0;
}
R|_|\/|\/|/-\|\|