CF143A.Help Vasilisa the Wise 2

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.

The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 × 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.

The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.

Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.

来自遥远王国的智者瓦西丽莎,收到了来自邻近王国的智者赫拉维萨赠送的一个装有秘密的魔法盒。然而,瓦西丽莎无法再次打开这个盒子,因此她并不知道盒中的秘密是什么。她希望你能再一次帮助她解决这个问题。

该盒子的锁结构如下:锁面上有 4 个完全相同的宝石凹槽,呈 2×22 \times 2 方阵排列;在锁面边缘靠近各凹槽的位置标有一些整数。下图展示了一个锁的示例:

盒子附带 9 颗宝石。这些宝石的形状与凹槽完全匹配,且每颗宝石上标有一个从 1 到 9 的数字(每个数字恰好出现在一颗宝石上)。只有当宝石被正确镶嵌时,盒子才会开启:即每个凹槽中必须恰好嵌入一颗宝石;同时,该 2×22 \times 2 方阵的两行、两列以及两条对角线上的数字之和,必须分别等于锁面边缘所标注的对应数值。例如,若按如下图所示的方式,将标有相应数字的宝石嵌入凹槽,则上图所示的锁即可开启:

现在,瓦西丽莎希望根据锁面上所标注的数字,确定应将哪几颗宝石嵌入凹槽才能打开盒子。请帮助瓦西丽莎完成这项富有挑战性的任务。

输入格式

The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers _r_1 and _r_2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers _c_1 and _c_2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers _d_1 and _d_2 that define the required sums of numbers on the main and on the side diagonals of the square (1 ≤ _r_1, _r_2, _c_1, _c_2, _d_1, _d_2 ≤ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.

输入包含写在盒子密码锁边上的数字。第一行包含用空格分隔的整数 r1r_1 和 r2r_2,它们分别表示正方形中两行数字之和的要求值;第二行包含用空格分隔的整数 c1c_1 和 c2c_2,它们分别表示正方形中两列数字之和的要求值;第三行包含用空格分隔的整数 d1d_1 和 d2d_2,它们分别表示正方形主对角线与副对角线上数字之和的要求值(其中 1≤r1,r2,c1,c2,d1,d2≤201 \leq r_1, r_2, c_1, c_2, d_1, d_2 \leq 20)。上述 6 个变量与它们在图中所标注位置之间的对应关系如下图所示。如需进一步理解,请参考第二个样例测试,它展示了题目描述中给出的示例。

输出格式

Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).

If there are several solutions, output any.

输出用宝石装饰盒子的方案:两行,每行包含两个用空格分隔的整数(取值范围为 1 到 9)。这些数字应两两互不相同。如果给定的锁无解,则输出单个数字 -1(不带引号)。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    3 7
    4 6
    5 5

    输出#1

    1 2
    3 4
  • 输入#2

    11 10
    13 8
    5 16

    输出#2

    4 7
    9 1
  • 输入#3

    1 2
    3 4
    5 6

    输出#3

    -1
  • 输入#4

    10 10
    10 10
    10 10

    输出#4

    -1

说明/提示

Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.

请注意题目描述中的最后一个测试用例:无法打开宝箱,因为瓦西丽萨女巫需要 4 颗标有数字“5”的相同宝石才能打开。然而,瓦西丽萨每种编号为 1 至 9 的宝石各只有一颗。

输入解题思路,AI测评打分。不知道怎么写?

首页