欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2047A.Alyona and a Square Jigsaw Puzzle
Alyona and a Square Jigsaw Puzzle
Alyona assembles an unusual square Jigsaw Puzzle. She does so in days in the following manner:
- On the first day, she starts by placing the central piece in the center of the table.
- On each day after the first one, she places a certain number of pieces around the central piece in clockwise order, always finishing each square layer completely before starting a new one.
For example, she places the first pieces in the following order:
The colors denote the layers. The third layer is still unfinished.
Alyona is happy if at the end of the day the assembled part of the puzzle does not have any started but unfinished layers. Given the number of pieces she assembles on each day, find the number of days Alyona is happy on.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line contains a single integer (), the number of days.
The second line contains integers (, ), where is the number of pieces Alyona assembles on the -th day.
It is guaranteed in each test case that at the end of the days, there are no unfinished layers.
Output
For each test case, print a single integer: the number of days when Alyona is happy.
Note
In the first test case, in the only day Alyona finishes the only layer.
In the second test case, on the first day, Alyona finishes the first layer, and on the second day, she finishes the second layer.
In the third test case, she finishes the second layer in a few days.
In the fourth test case, she finishes the second layer and immediately starts the next one on the same day, therefore, she is not happy on that day. She is only happy on the first and last days.
In the fifth test case, Alyona is happy on the first, fourth, and last days.
Samples
5
1
1
2
1 8
5
1 3 2 1 2
7
1 2 1 10 2 7 2
14
1 10 10 100 1 1 10 1 10 2 10 2 10 1
1
2
2
2
3
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |