#4429. [Nwerc2015] Elementary Math小学数学

[Nwerc2015] Elementary Math小学数学

题目描述

Ellen is teaching elementary math to her students and the time for the final exam has come. The exam consists of nn questions. In each question the students have to add (+), subtract (−) or multiply (∗) a pair of numbers.
Ellen has already chosen the nn pairs of numbers. All that remains is to decide for each pair which of the three possible operations the students should perform. To avoid students getting bored, Ellen wants to make sure that the nn correct answers to her exam are all different.
Please help Ellen finish constructing the exam by automating this task.

Ellen 给她的学生教小学数学。期末考试已经来临了。考试有 nn 个题目,每一个题目学生们都要对一对数字进行加(+),减(-),乘(*)运算。
Ellen已经选好了 nn 对数。剩下的是决定学生们应该对每对数执行什么运算。为了不让学生们感到厌烦,Ellen 想确保 nn 个正确答案都不一样。
请帮助 Ellen 自动化地构建考试。

输入格式

The input consists of:

  • one line with one integer nn, the number of pairs of numbers;
  • nn lines each with two integers aa and bb, a pair of numbers used.

输入包括:
第一行是一个整数 nn,表示共有 nn 道题目。
接下来 nn 行每行有 22 个整数 aabb,表示每一题使用的整数。

输出格式

For each pair of numbers (a,b)(a, b) in the same order as in the input, output a line containing a valid equation. Each equation should consist of five parts: aa, one of the three operators, bb, an equals sign (=), and the result of the expression. All the nn expression results must be different.
If there are multiple valid answers you may output any of them. If there is no valid answer, output a single line with the string “impossible” instead. 对于输入中的每一对 (a,b)(a,b),输出一行有效的方程。每一个方程应该包含5部分:aa+-* 中的一个运算符,bb=,答案。nn 个答案必须不同。
如果有多个有效答案,你可以输出任意一个。如果没有答案,输出「impossible」。

4
1 5
3 3
4 5
-1 -6
1+5=6
3*3=9
4-5=-1
-1--6=5
4
-4 2
-4 2
-4 2
-4 2
impossible

数据范围与约定

对于 100%100 \% 的数据,1n25001 \le n \le 2500106a,b106-10^6 \le a, b \le 10^6