A9247 | Domino
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Valera has got $n$ domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from $1$ to $6$ . Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by $180$ degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
To do that, Valera can rotate the dominoes by $180$ degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
输入格式
The first line contains integer $n$ $(1<=n<=100)$ , denoting the number of dominoes Valera has. Next $n$ lines contain two space-separated integers $x_{i},y_{i}$ $(1<=x_{i},y_{i}<=6)$ . Number $x_{i}$ is initially written on the upper half of the $i$ -th domino, $y_{i}$ is initially written on the lower half.
输出格式
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print $-1$ .
输入输出样例
输入 #1
2 4 2 6 4
输出 #1
0
输入 #2
1 2 3
输出 #2
-1
输入 #3
3 1 4 2 3 4 4
输出 #3
1
In the first test case the sum of the numbers on the upper halves equals $10$ and the sum of the numbers on the lower halves equals $6$ . Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written $3$ on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to $10$ , and the sum on the lower halves will be equal to $8$ .
In the second sample Valera has only one piece of domino. It is written $3$ on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to $10$ , and the sum on the lower halves will be equal to $8$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted