A10451 | Chain Reaction
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Group of Berland scientists, with whom you have a close business relationship, makes a research in the area of peaceful nuclear energy. In particular, they found that a group of four nanobots, placed on a surface of a plate, can run a powerful chain reaction under certain conditions.
To be precise, researchers introduced a rectangular Cartesian coordinate system on a flat plate and selected four distinct points with integer coordinates where bots will be placed initially. Next each bot will be assigned with one of the four directions (up, down, left or right) parallel to the coordinate axes. After that, each bot is shifted by an integer distance (which may be different for different bots) along its direction. The chain reaction starts, if the bots are in the corners of a square with positive area with sides parallel to the coordinate axes. Each corner of the square must contain one nanobot. This reaction will be stronger, if bots spend less time to move. We can assume that bots move with unit speed. In other words, the lesser is the maximum length traveled by bot, the stronger is reaction.
Scientists have prepared a set of plates and selected starting position for the bots for each plate. Now they ask you to assign the direction for each bot to move after landing such that the maximum length traveled by bot is as small as possible.
To be precise, researchers introduced a rectangular Cartesian coordinate system on a flat plate and selected four distinct points with integer coordinates where bots will be placed initially. Next each bot will be assigned with one of the four directions (up, down, left or right) parallel to the coordinate axes. After that, each bot is shifted by an integer distance (which may be different for different bots) along its direction. The chain reaction starts, if the bots are in the corners of a square with positive area with sides parallel to the coordinate axes. Each corner of the square must contain one nanobot. This reaction will be stronger, if bots spend less time to move. We can assume that bots move with unit speed. In other words, the lesser is the maximum length traveled by bot, the stronger is reaction.
Scientists have prepared a set of plates and selected starting position for the bots for each plate. Now they ask you to assign the direction for each bot to move after landing such that the maximum length traveled by bot is as small as possible.
输入格式
The first line contains an integer number $t$ ( $1<=t<=50$ ) — the number of plates.
$t$ descriptions of plates follow. A description of each plate consists of four lines. Each line consists of a pair of integers numbers $x_{i},y_{i}$ ( $-10^{8}<=x_{i},y_{i}<=10^{8}$ ) — coordinates of the next bot. All bots are in different locations.
Note, though, the problem can include several records in one test, you can hack other people's submissions only with the test of one plate, i.e. parameter $t$ in a hack test should be equal to $1$ .
$t$ descriptions of plates follow. A description of each plate consists of four lines. Each line consists of a pair of integers numbers $x_{i},y_{i}$ ( $-10^{8}<=x_{i},y_{i}<=10^{8}$ ) — coordinates of the next bot. All bots are in different locations.
Note, though, the problem can include several records in one test, you can hack other people's submissions only with the test of one plate, i.e. parameter $t$ in a hack test should be equal to $1$ .
输出格式
Print answers for all plates separately. First goes a single integer number in a separate line. If scientists have made an unfortunate mistake and nanobots are not able to form the desired square, print -1. Otherwise, print the minimum possible length of the longest bot's path.
If a solution exists, in the next four lines print two integer numbers — positions of each bot after moving. Print bots' positions in the order they are specified in the input data.
If there are multiple solution, you can print any of them.
If a solution exists, in the next four lines print two integer numbers — positions of each bot after moving. Print bots' positions in the order they are specified in the input data.
If there are multiple solution, you can print any of them.
输入输出样例
输入 #1
2 1 1 1 -1 -1 1 -1 -1 1 1 2 2 4 4 6 6
输出 #1
0 1 1 1 -1 -1 1 -1 -1 -1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted