A14422 | Polycarp and Coins
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp must pay exactly $n$ burles at the checkout. He has coins of two nominal values: $1$ burle and $2$ burles. Polycarp likes both kinds of coins equally. So he doesn't want to pay with more coins of one type than with the other.
Thus, Polycarp wants to minimize the difference between the count of coins of $1$ burle and $2$ burles being used. Help him by determining two non-negative integer values $c_1$ and $c_2$ which are the number of coins of $1$ burle and $2$ burles, respectively, so that the total value of that number of coins is exactly $n$ (i. e. $c_1 + 2 \cdot c_2 = n$ ), and the absolute value of the difference between $c_1$ and $c_2$ is as little as possible (i. e. you must minimize $|c_1-c_2|$ ).
Thus, Polycarp wants to minimize the difference between the count of coins of $1$ burle and $2$ burles being used. Help him by determining two non-negative integer values $c_1$ and $c_2$ which are the number of coins of $1$ burle and $2$ burles, respectively, so that the total value of that number of coins is exactly $n$ (i. e. $c_1 + 2 \cdot c_2 = n$ ), and the absolute value of the difference between $c_1$ and $c_2$ is as little as possible (i. e. you must minimize $|c_1-c_2|$ ).
输入格式
The first line contains one integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases. Then $t$ test cases follow.
Each test case consists of one line. This line contains one integer $n$ ( $1 \le n \le 10^9$ ) — the number of burles to be paid by Polycarp.
Each test case consists of one line. This line contains one integer $n$ ( $1 \le n \le 10^9$ ) — the number of burles to be paid by Polycarp.
输出格式
For each test case, output a separate line containing two integers $c_1$ and $c_2$ ( $c_1, c_2 \ge 0$ ) separated by a space where $c_1$ is the number of coins of $1$ burle and $c_2$ is the number of coins of $2$ burles. If there are multiple optimal solutions, print any one.
输入输出样例
输入 #1
6 1000 30 1 32 1000000000 5
输出 #1
334 333 10 10 1 0 10 11 333333334 333333333 1 2
The answer for the first test case is "334 333". The sum of the nominal values of all coins is $334 \cdot 1 + 333 \cdot 2 = 1000$ , whereas $|334 - 333| = 1$ . One can't get the better value because if $|c_1 - c_2| = 0$ , then $c_1 = c_2$ and $c_1 \cdot 1 + c_1 \cdot 2 = 1000$ , but then the value of $c_1$ isn't an integer.
The answer for the second test case is "10 10". The sum of the nominal values is $10 \cdot 1 + 10 \cdot 2 = 30$ and $|10 - 10| = 0$ , whereas there's no number having an absolute value less than $0$ .
The answer for the second test case is "10 10". The sum of the nominal values is $10 \cdot 1 + 10 \cdot 2 = 30$ and $|10 - 10| = 0$ , whereas there's no number having an absolute value less than $0$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted