A15440 | Working Week
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Your working week consists of $n$ days numbered from $1$ to $n$ , after day $n$ goes day $1$ again. And $3$ of them are days off. One of the days off is the last day, day $n$ . You have to decide when the other two are.
Choosing days off, you pursue two goals:
- No two days should go one after the other. Note that you can't make day $1$ a day off because it follows day $n$ .
- Working segments framed by days off should be as dissimilar as possible in duration. More specifically, if the segments are of size $l_1$ , $l_2$ , and $l_3$ days long, you want to maximize $\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|)$ .
Output the maximum value of $\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|)$ that can be obtained.
Choosing days off, you pursue two goals:
- No two days should go one after the other. Note that you can't make day $1$ a day off because it follows day $n$ .
- Working segments framed by days off should be as dissimilar as possible in duration. More specifically, if the segments are of size $l_1$ , $l_2$ , and $l_3$ days long, you want to maximize $\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|)$ .
Output the maximum value of $\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|)$ that can be obtained.
输入格式
The first line of the input contains a single integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases. The description of test cases follows.
The only line of each test case contains the integer $n$ ( $6 \le n \le 10^9$ ).
The only line of each test case contains the integer $n$ ( $6 \le n \le 10^9$ ).
输出格式
For each test case, output one integer — the maximum possible obtained value.
输入输出样例
输入 #1
3 6 10 1033
输出 #1
0 1 342
In the image below you can see the example solutions for the first two test cases. Chosen days off are shown in purple. Working segments are underlined in green.
In test case $1$ , the only options for days off are days $2$ , $3$ , and $4$ (because $1$ and $5$ are next to day $n$ ). So the only way to place them without selecting neighboring days is to choose days $2$ and $4$ . Thus, $l_1 = l_2 = l_3 = 1$ , and the answer $\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|) = 0$ .
For test case $2$ , one possible way to choose days off is shown. The working segments have the lengths of $2$ , $1$ , and $4$ days. So the minimum difference is $1 = \min(1, 3, 2) = \min(|2 - 1|, |1 - 4|, |4 - 2|)$ . It can be shown that there is no way to make it larger.

In test case $1$ , the only options for days off are days $2$ , $3$ , and $4$ (because $1$ and $5$ are next to day $n$ ). So the only way to place them without selecting neighboring days is to choose days $2$ and $4$ . Thus, $l_1 = l_2 = l_3 = 1$ , and the answer $\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|) = 0$ .
For test case $2$ , one possible way to choose days off is shown. The working segments have the lengths of $2$ , $1$ , and $4$ days. So the minimum difference is $1 = \min(1, 3, 2) = \min(|2 - 1|, |1 - 4|, |4 - 2|)$ . It can be shown that there is no way to make it larger.

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted