Posted:

**Sun Sep 05, 2004 1:06 am**The UVa Online Judge board

https://uva.onlinejudge.org/board/

Page **3** of **6**

Posted: **Sun Sep 05, 2004 1:06 am**

Posted: **Sun Sep 05, 2004 6:20 am**

Thanks malf but I try all that input and i got the same answer please help me someone that explain me why is wrong

[c]

#include <stdio.h>

#include <math.h>

int main(){

unsigned long tb=0,tt=0,bt=0,btt5=0,btt=0;

double tre=0,tr=0;

int set=1,count=0;

while(1){

scanf("%lu",&tb);

if(tb == 0)

break;

printf("Output for data set %d, %lu bytes:\n",set++,tb);

tt=btt=count=bt=btt5=0;

while(btt < tb){

scanf("%lu",&bt);

if(bt == 0){

count++;

}

btt += bt;

btt5 += bt;

tt++;

if(tt%5 == 0 && count != 5 && btt5 != 0){

tr = (double)btt5 / 5.0;

tre = (double)(tb - btt)/(tr);

printf(" Time remaining: %ld seconds\n",(long)ceil(tre));

btt5=count=0;

}

if(count == 5){

printf(" Time remaining: stalled\n");

btt5=count=0;

}

}

printf("Total time: %lu seconds\n\n",tt);

}

return 0;

}[/c]

[c]

#include <stdio.h>

#include <math.h>

int main(){

unsigned long tb=0,tt=0,bt=0,btt5=0,btt=0;

double tre=0,tr=0;

int set=1,count=0;

while(1){

scanf("%lu",&tb);

if(tb == 0)

break;

printf("Output for data set %d, %lu bytes:\n",set++,tb);

tt=btt=count=bt=btt5=0;

while(btt < tb){

scanf("%lu",&bt);

if(bt == 0){

count++;

}

btt += bt;

btt5 += bt;

tt++;

if(tt%5 == 0 && count != 5 && btt5 != 0){

tr = (double)btt5 / 5.0;

tre = (double)(tb - btt)/(tr);

printf(" Time remaining: %ld seconds\n",(long)ceil(tre));

btt5=count=0;

}

if(count == 5){

printf(" Time remaining: stalled\n");

btt5=count=0;

}

}

printf("Total time: %lu seconds\n\n",tt);

}

return 0;

}[/c]

Posted: **Sun Sep 05, 2004 4:59 pm**

Maybe is the precision of your "tb" variable...

Still looking

Still looking

Posted: **Thu Sep 09, 2004 6:24 pm**

Can anybody check my code too (I have right answers for every input I find in all the posts in this forum):

[cpp]

#include <iostream>

#include <math.h>

using namespace std;

long long set,csuma,tsuma,tbytes,rbytes[5],i,secleft,k;

double bitrate;

void czytaj()

{

cout << "Output for data set " << set << ", " << tbytes << " bytes:" << endl;

for (i=0,tsuma=0,csuma=0,k=1;;k++)

{

cin >> rbytes*;*

tsuma+=rbytes*;*

csuma+=rbytes[i++];

if (i==5)

{

i=0;

if (csuma==0)

{

cout << " Time remaining: stalled" << endl;

continue;

}

bitrate=double(csuma/5.0);

csuma=0;

secleft=(long long)ceil(double(tbytes-tsuma)/(double)bitrate);

cout << " Time remaining: " << secleft << " seconds" << endl;

}

if (tsuma==tbytes) break;

}

cout << "Total time: " << k << " seconds" << endl << endl;

}

int main()

{

for (set=1;;set++)

{

cin >> tbytes;

if (tbytes==0) break;

czytaj();

}

return 0;

}

[/cpp]

[cpp]

#include <iostream>

#include <math.h>

using namespace std;

long long set,csuma,tsuma,tbytes,rbytes[5],i,secleft,k;

double bitrate;

void czytaj()

{

cout << "Output for data set " << set << ", " << tbytes << " bytes:" << endl;

for (i=0,tsuma=0,csuma=0,k=1;;k++)

{

cin >> rbytes

tsuma+=rbytes

csuma+=rbytes[i++];

if (i==5)

{

i=0;

if (csuma==0)

{

cout << " Time remaining: stalled" << endl;

continue;

}

bitrate=double(csuma/5.0);

csuma=0;

secleft=(long long)ceil(double(tbytes-tsuma)/(double)bitrate);

cout << " Time remaining: " << secleft << " seconds" << endl;

}

if (tsuma==tbytes) break;

}

cout << "Total time: " << k << " seconds" << endl << endl;

}

int main()

{

for (set=1;;set++)

{

cin >> tbytes;

if (tbytes==0) break;

czytaj();

}

return 0;

}

[/cpp]

Posted: **Tue Sep 14, 2004 1:00 am**

Hi can someone help me and give me some inputs where my code give the bad inputs please help me i with this prob please help

Posted: **Sat Oct 02, 2004 8:05 am**

it's really a simple problem,but why i keep getting WA???

[cpp]

#include <iostream>

using namespace std;

unsigned long ceiling(double x)

{

if(x - (unsigned long)(x) != 0) return (unsigned long)x + 1;

else return (unsigned long)(x);

}

int main()

{

unsigned long size,sum,count,t,n = 0,totalTime,flag = 1;

double aver;

while(cin >> size)

{

if(size == 0) break;

cout << "Output for data set "<< ++n << ", " << size << " bytes:" << endl;

totalTime = aver = count = sum = 0;

while(sum != size)

{

totalTime++;

count++;

cin >> t;

sum += t;

aver += t;

if(count == 5)

{

count = 0;

aver /= 5;

if(aver == 0)

{

cout << " Time remaining: stalled" << endl;

}

else

{

cout << " Time remaining: " << ceiling((size - sum) / aver) << " seconds" << endl;

}

aver = 0;

}

}

cout << "Total time: " << totalTime <<" seconds" << endl << endl;

}

}

[/cpp]

[cpp]

#include <iostream>

using namespace std;

unsigned long ceiling(double x)

{

if(x - (unsigned long)(x) != 0) return (unsigned long)x + 1;

else return (unsigned long)(x);

}

int main()

{

unsigned long size,sum,count,t,n = 0,totalTime,flag = 1;

double aver;

while(cin >> size)

{

if(size == 0) break;

cout << "Output for data set "<< ++n << ", " << size << " bytes:" << endl;

totalTime = aver = count = sum = 0;

while(sum != size)

{

totalTime++;

count++;

cin >> t;

sum += t;

aver += t;

if(count == 5)

{

count = 0;

aver /= 5;

if(aver == 0)

{

cout << " Time remaining: stalled" << endl;

}

else

{

cout << " Time remaining: " << ceiling((size - sum) / aver) << " seconds" << endl;

}

aver = 0;

}

}

cout << "Total time: " << totalTime <<" seconds" << endl << endl;

}

}

[/cpp]

Posted: **Thu Dec 23, 2004 1:54 am**

Hi, I got Acc after 7 WA and all credit goes towards u sjn. This problem made me sick....

Posted: **Tue Apr 19, 2005 12:30 pm**

seriously, this is one of the problems that make you hate problem solving...

it's fairly simple, but it has a catch. like SJN said, you must do EXACTLY the following, or you won't get ACC.

remainSecond = remainBytes / (transferedBytes/5.0);

printf("%d seconds\n", ceil(remainSecond));

thx SJN for your insight.

but i still don't get it.

it's fairly simple, but it has a catch. like SJN said, you must do EXACTLY the following, or you won't get ACC.

remainSecond = remainBytes / (transferedBytes/5.0);

printf("%d seconds\n", ceil(remainSecond));

thx SJN for your insight.

but i still don't get it.

Posted: **Tue Sep 27, 2005 8:47 am**

Hi I check all the test cases that I can found they match with the output but still getting WA. I am using long and double data structure is that is the cause?

some one please help me out.

some one please help me out.

Code: Select all

```
/*
Name: 18000 seconds remaining
Number: 362
Type : ad hoc
Process : ON
Author :Salman Zaman
Email : zamansalman@gmail.com
Date : 02/06/05 01:27
*/
#include<stdio.h>
#include<math.h>
int main()
{
long total,subtotal,input,sflag;
long flag=0,count=0,scount,secondtotal;
double rsecond,trate,bremain;
// freopen("362.txt","r",stdin);
subtotal=0;
flag=0;
sflag=0;
count=1;
scount=0;
secondtotal=0;
bremain=0;
while(scanf("%ld",&input)!=EOF)
{
if(input==0 && flag==0)
{
break;
}
if(flag)
{
subtotal+=input;
secondtotal+=input;
scount++;
// printf("%d\n",scount);
}
if(scount!=0 && scount%5==0)
{
if(!secondtotal)
{
printf(" Time remaining: stalled\n");
}
else
{
trate =(double)secondtotal/5;
//printf("%d %d %lf %lf\n",scount,secondtotal,trate,bremain);
bremain=bremain-secondtotal;
//printf("%d %d %lf %lf\n",scount,secondtotal,trate,bremain);
rsecond=(bremain)/trate;
rsecond = ceil(rsecond);
//printf("%lf\n",rsecond);
printf(" Time remaining: %.0lf seconds\n",rsecond);
}
secondtotal=0;
}
if(!flag)
{
bremain=total=input;
if(sflag)
{
printf("\n");
}
printf("Output for data set %ld, %ld bytes:\n",count,total);
flag=1;
}
if(subtotal==total)
{
subtotal=0;
secondtotal=0;
bremain=0;
printf("Total time: %ld seconds\n",scount);
sflag=1;
flag=0;
scount=0;
count++;
}
}
return 0;
}
```

Posted: **Wed Dec 07, 2005 1:25 pm**

I'm trying to solve 362 problem and I made more than 10 submissions and got very WA and 2 TLE. My program works for all the test cases you put in this board, but the judge still don't accept!

I think I'll leave this...

I do not know what's wrong. Does anybody know if I must use a struct for big integer numbers? Or using double, like the last post, is enogh.

Thanks!

--I'm getting crazy!

I think I'll leave this...

I do not know what's wrong. Does anybody know if I must use a struct for big integer numbers? Or using double, like the last post, is enogh.

Thanks!

--I'm getting crazy!

Posted: **Wed Dec 07, 2005 3:10 pm**

32 bits long should be enough! I did ceiling() though during division.

Posted: **Sat Jan 14, 2006 7:21 am**

Yeah I also got AC after doing the following:

float remainSecond = remainBytes / (transferedBytes/5.0);

instead of something like:

float transferrate = (transferedBytes/5.0)

float remainSecond = remainBytes / transferrate;

Other than that, you can just use int and float for all your variables. No tricky input, though I wonder what it uses so much memory for. One additional security measure I took is (int)(ceil(remaining)+0.2) which I don't believe is really needed though based on the thread.

float remainSecond = remainBytes / (transferedBytes/5.0);

instead of something like:

float transferrate = (transferedBytes/5.0)

float remainSecond = remainBytes / transferrate;

Other than that, you can just use int and float for all your variables. No tricky input, though I wonder what it uses so much memory for. One additional security measure I took is (int)(ceil(remaining)+0.2) which I don't believe is really needed though based on the thread.

Posted: **Mon Apr 03, 2006 12:55 pm**

I also got AC after what sjn told us to do. I was frustrated at not having been able to submit it for 3 days.

Posted: **Fri May 12, 2006 9:55 pm**

Man....

such problems are crap....

though I didn't divide by 5.0....

instead i used rate=0.2*transferredbytes;

and then remaintime=ceil(remainbytes/rate);

then used %.0lf to printf the answer....

but if i used rate=transferredbytes/5.0;

then that ceil problem cropped up.... giving me WA.

another thing is that using '\t' for the 'Time remaining' message, gave me PE, whereas, using 'bbbTime remaining:'' (b=blank) gave me AC....

strange.....

does \t signify different lengths in different platforms ???

such problems are crap....

though I didn't divide by 5.0....

instead i used rate=0.2*transferredbytes;

and then remaintime=ceil(remainbytes/rate);

then used %.0lf to printf the answer....

but if i used rate=transferredbytes/5.0;

then that ceil problem cropped up.... giving me WA.

another thing is that using '\t' for the 'Time remaining' message, gave me PE, whereas, using 'bbbTime remaining:'' (b=blank) gave me AC....

strange.....

does \t signify different lengths in different platforms ???

Posted: **Fri Jun 23, 2006 6:07 am**

Hi All,

I was getting WA for this problem, too till I edited something in the calculation of the remaining time.

Instead of writing:

Then using ceil (rem) to display the remaining time.

U should write:

Then use ceil (rem);

I wrote the second and got PE.

I hope this helps.

By the way, there is a discussion about this here. I knew about this from there

I was getting WA for this problem, too till I edited something in the calculation of the remaining time.

Instead of writing:

Code: Select all

```
rate=size/5.0;
rem=remsize/rate;
```

U should write:

Code: Select all

```
rem=remsize/(size/5.0);
```

I wrote the second and got PE.

I hope this helps.

By the way, there is a discussion about this here. I knew about this from there