#P1812. 区间运算
区间运算
Description
Interval arithmetic is a branch of mathematics. In interval arithmetic, constants and variables are not represented by a single exact value, but by an interval or range with a lower and an upper bound. In ordinary arithmetic, a quantity can be represented as a point on the number line; in interval arithmetic, a quantity is represented as a segment on the number line, for example, denotes the segment from to . When an exact number is represented as an interval, the upper and lower bounds are identical, e.g., as an interval is .
An operation on two intervals means applying the operation to every point in one interval with every point in the other interval; the set of all resulting points is the result of the operation. For example, . Your task is to write a program that can perform the basic interval operations of unary negation, addition, subtraction, multiplication, and division according to a single-line expression. Here are some examples:
- Negation: .
- Addition: .
- Subtraction: .
- Multiplication: .
- Division: .
Input Format
The input consists of one or more lines, each containing an infix expression over intervals. Each interval is written as . Expressions may include parentheses, the minus sign (), plus (), minus (), multiplication (), and division (); parentheses may be nested. A line may contain spaces, but no space appears inside the brackets of an interval or immediately after a minus sign. Scientific notation need not be handled, e.g., . Each line contains at most characters. Operations follow the standard precedence rules. Operators are listed below in decreasing order of precedence:
- parentheses.
- unary negation.
- multiplication and division; operators of the same precedence are evaluated from left to right.
- addition and subtraction; operators of the same precedence are evaluated from left to right.
Output Format
For each input line, output the result as (both endpoints rounded to decimal places). Print one result per line. There must be no spaces in the output. During evaluation, if an interval that contains is used as a divisor, output Division by zero.
-[-3,5]
[3,5]+[-10,1]
[3,5]-[-10,1]
[3,5]*[-10,1]
(([3,5]/[-10,-0.1])/-[2,2])
[-5.000,3.000]
[-7.000,6.000]
[2.000,15.000]
[-50.000,5.000]
[0.150,25.000]
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号