#B3910. Zero Counting Based on the Intermediate Value Theorem
Zero Counting Based on the Intermediate Value Theorem
Zero Counting Based on the Intermediate Value Theorem
In this problem, you are given a mysterious continuous function \( \phi(x) \). It is known that for any interval \((a, b)\) where \(\phi(a)\) and \(\phi(b)\) have opposite signs, i.e. \(\phi(a)\cdot\phi(b) < 0\), by the Intermediate Value Theorem (零点存在定理), there is at least one zero of \(\phi(x)\) in the interval \((a,b)\).
Little F has computed the values of \(\phi(x)\) at every integer point between \(0\) and \(N\), inclusive. Based on these values, determine the minimum number of zeros that can be guaranteed to exist in the open interval \((0, N)\) by applying the above theorem.
The idea is that if for any two consecutive integers \(w\) and \(w+1\) (where \(0 \le w < N\)), the product \(\phi(w) \cdot \phi(w+1) < 0\), then there is at least one zero in the interval \((w, w+1)\). Your task is to count how many such intervals exist.
Note: If any \(\phi(w) = 0\), do not count the interval since the condition requires the product to be strictly less than zero.
inputFormat
The first line of the input contains an integer \(N\) (\(1 \le N \le 10^5\)), representing the upper bound of the interval \([0, N]\).
The second line contains \(N+1\) numbers: \(\phi(0), \phi(1), \ldots, \phi(N)\). Each value is a real number and can be positive, negative, or zero.
outputFormat
Output a single integer representing the minimum number of zeros guaranteed to exist in the open interval \((0, N)\) based on the Intermediate Value Theorem.
sample
3
1 -2 -3 4
2