But Why?
If anybody can give the answer i will be very grateful to him.
Code: Select all
Removed after got AC
Moderator: Board moderators
Code: Select all
Removed after got AC
Code: Select all
#include<stdio.h>
#include<math.h>
int main(void)
{
double tb,takenTotal,takenPrev5,take;
long t,dataset = 1;
bool tag = false;
scanf("%lf",&tb);
while(tb!=0)
{
if(tag == false) tag = true;
else printf("\n");
...
...
...
...
...
dataset++;
}
return 0;
}
Code: Select all
/* 18,000 Seconds Remaining */
#include <stdio.h>
int main ()
{
/* FILE *in = freopen ("c.in", "r", stdin); /**/
long b=0, B=0, c=0;
scanf("%i", &b);
while (b!=0)
{
c++;
/* if (c!=1)
printf("\n");
*/
long sec=0, time[5];
printf("Output for data set %d, %d bytes:\n", c, b);
B=0;
while (B<b)
{
scanf("%i", &time[sec%5]);
B += time[sec%5];
sec++;
if (sec%5==0)
{
long suma=0, x=0;
double t=0.0;
while(x++<5)
suma += time[x-1];
t = suma/5.0;
double d=0;
if (t!=0)
{
x = (b-B)/t;
d = (b-B)/t;
if (x!=d)
x++;
}
printf(" Time remaining: ");
if (t==0)
printf("stalled\n");
else
printf("%i seconds\n", x);
}
}
printf("Total time: %i seconds\n", sec);
scanf("%i", &b);
if (b!=0)
printf("\n");
}
return 0;
}
Code: Select all
aver /= 5;
Code: Select all
aver /= 5.0;
Code: Select all
cout << " Time remaining: " << ceiling((size - sum) / aver) << " seconds" << endl;
Code: Select all
cout << " Time remaining: " << ceiling((size - sum) / aver) << " seconds" << endl;
Code: Select all
Got AC.
Changed the line
printf(" Time remaining: %.0f seconds\n",ceil(remainingBytes/((float)transferedBytes/5.0)));
to
printf(" Time remaining: %.0f seconds\n",ceil(remainingBytes/((double)transferedBytes*0.2)));
and GOT AC.
Code: Select all
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int index = 0;
int totalBytes = scan.nextInt();
while (totalBytes > 0) {
System.out.println("Output for data set " + (++index) + ", "
+ totalBytes + " bytes:");
int bytesRead = 0, seconds = 0, count = 0;
double transWindow = 0;
//while more bytes to read
while (totalBytes > bytesRead) {
++seconds;
++count;
int temp = scan.nextInt();
transWindow += temp;
bytesRead += temp;
if (count == 5) {
if (transWindow > 0) {
System.out.println(" Time remaining: "
+ (int) Math.ceil((totalBytes - bytesRead)
/ (transWindow / 5.0)) + " seconds");
} else {
System.out.println(" Time remaining: stalled");
}
count =0;
transWindow=0;
}
}
System.out.println("Total time: " + seconds + " seconds\n");
totalBytes = scan.nextInt();
}
}
}
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
long size,time,count,sum,n=1,byte,line=0;
double aver,remainsecond;
while(scanf("%ld",&size)==1&& size){
if(line)printf("\n");
line=1;
printf("Output for data set %ld, %ld bytes:\n",n++,size);
sum=0;time=0;count=0;aver=0;
while(sum!=size){
scanf("%ld",&byte);
sum+=byte;
aver+=byte;
count++;
time++;
if(count==5){
count=0;
if(aver==0)printf(" Time remaining: stalled\n");
else {
remainsecond=(size-sum)/(aver/5.0);
printf(" Time remaining: %.0lf seconds\n",ceil(remainsecond));
}
aver=0;
}
}
printf("Total time: %ld seconds\n",time);
}
return 0;
}