362  18,000 Seconds Remaining
Moderator: Board moderators
 Ghust_omega
 Experienced poster
 Posts: 115
 Joined: Tue Apr 06, 2004 7:04 pm
 Location: Venezuela
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]
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(tbytestsuma)/(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(tbytestsuma)/(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]
 Ghust_omega
 Experienced poster
 Posts: 115
 Joined: Tue Apr 06, 2004 7:04 pm
 Location: Venezuela
362 why WA???
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]
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know this will lead to knowledge."Confucius
"Hold what you really know and tell what you do not know this will lead to knowledge."Confucius

 New poster
 Posts: 36
 Joined: Tue Apr 12, 2005 12:20 am
 Location: belgrade, serbia (ex yugoslavia)
 Contact:
ACCEPTED, finaly....
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.
362 is kill me
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=bremainsecondtotal;
//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;
}
I can't understand!
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!
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.

 New poster
 Posts: 5
 Joined: Mon Apr 03, 2006 12:52 pm
Thanks
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.
i'm relieved...
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 ???
maKe wHat yoU waNt...... you'll succeed

 New poster
 Posts: 27
 Joined: Tue Dec 20, 2005 9:14 am
 Location: Egypt
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