F
F
freecam2020-08-24 17:10:03
Algorithms
freecam, 2020-08-24 17:10:03

In which case the program produces a false result?

I was solving problems and I had a problem when solving this one:

The task
Takahashi loves takoyaki - a ball-shaped snack. With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make. How long does it take to make N takoyaki?

Solved it like this:
#include <iostream>
using namespace std;
int main()
{
int x,n,t;
double t2;
cin » n » x » t;
t2 = (double)(n*t)/x;
t = (n*t)/x;
if(t < t2) {
cout « t+1 « endl;
} else {
cout « t « endl;
};
return 0;
}


1≤N,X,T≤1000
All values ​​in input are integers.
In what cases will the answer be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2020-08-24
@freecam

T = 4, X = 2, N = 1. 2 minutes are obtained, although four are needed.
You don't need ceilDiv(nt, x), at ceilDiv(n,x).
Well, with such restrictions ceilDiv(n, x) = (n + x - 1) / x, without fractional arithmetic.
(When collecting everything into one expression, don't forget the parentheses!)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question