A8977 | Ants
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: every minute at each junction ( $x$ , $y$ ) containing at least four ants a group of four ants will be formed, and these four ants will scatter to the neighbouring junctions ( $x+1$ , $y$ ), ( $x-1$ , $y$ ), ( $x$ , $y+1$ ), ( $x$ , $y-1$ ) — one ant in each direction. No other ant movements will happen. Ants never interfere with each other.
Scientists have put a colony of $n$ ants into the junction (0, 0) and now they wish to know how many ants will there be at some given junctions, when the movement of the ants stops.
Scientists have put a colony of $n$ ants into the junction (0, 0) and now they wish to know how many ants will there be at some given junctions, when the movement of the ants stops.
输入格式
First input line contains integers $n$ ( $0<=n<=30000$ ) and $t$ ( $1<=t<=50000$ ), where $n$ is the number of ants in the colony and $t$ is the number of queries. Each of the next $t$ lines contains coordinates of a query junction: integers $x_{i}$ , $y_{i}$ ( $-10^{9}<=x_{i},y_{i}<=10^{9}$ ). Queries may coincide.
It is guaranteed that there will be a certain moment of time when no possible movements can happen (in other words, the process will eventually end).
It is guaranteed that there will be a certain moment of time when no possible movements can happen (in other words, the process will eventually end).
输出格式
Print $t$ integers, one per line — the number of ants at the corresponding junctions when the movement of the ants stops.
输入输出样例
输入 #1
1 3 0 1 0 0 0 -1
输出 #1
0 1 0
输入 #2
6 5 0 -2 0 -1 0 0 0 1 0 2
输出 #2
0 1 2 1 0
In the first sample the colony consists of the one ant, so nothing happens at all.
In the second sample the colony consists of 6 ants. At the first minute 4 ants scatter from (0, 0) to the neighbouring junctions. After that the process stops.
In the second sample the colony consists of 6 ants. At the first minute 4 ants scatter from (0, 0) to the neighbouring junctions. After that the process stops.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted