A14550 | Rings
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Frodo was caught by Saruman. He tore a pouch from Frodo's neck, shook out its contents —there was a pile of different rings: gold and silver..."How am I to tell which is the One?!" the mage howled.
"Throw them one by one into the Cracks of Doom and watch when Mordor falls!"
Somewhere in a parallel Middle-earth, when Saruman caught Frodo, he only found $n$ rings. And the $i$ -th ring was either gold or silver. For convenience Saruman wrote down a binary string $s$ of $n$ characters, where the $i$ -th character was 0 if the $i$ -th ring was gold, and 1 if it was silver.
Saruman has a magic function $f$ , which takes a binary string and returns a number obtained by converting the string into a binary number and then converting the binary number into a decimal number. For example, $f(001010) = 10, f(111) = 7, f(11011101) = 221$ .
Saruman, however, thinks that the order of the rings plays some important role. He wants to find $2$ pairs of integers $(l_1, r_1), (l_2, r_2)$ , such that:
- $1 \le l_1 \le n$ , $1 \le r_1 \le n$ , $r_1-l_1+1\ge \lfloor \frac{n}{2} \rfloor$
- $1 \le l_2 \le n$ , $1 \le r_2 \le n$ , $r_2-l_2+1\ge \lfloor \frac{n}{2} \rfloor$
- Pairs $(l_1, r_1)$ and $(l_2, r_2)$ are distinct. That is, at least one of $l_1 \neq l_2$ and $r_1 \neq r_2$ must hold.
- Let $t$ be the substring $s[l_1:r_1]$ of $s$ , and $w$ be the substring $s[l_2:r_2]$ of $s$ . Then there exists non-negative integer $k$ , such that $f(t) = f(w) \cdot k$ .
Here substring $s[l:r]$ denotes $s_ls_{l+1}\ldots s_{r-1}s_r$ , and $\lfloor x \rfloor$ denotes rounding the number down to the nearest integer.
Help Saruman solve this problem! It is guaranteed that under the constraints of the problem at least one solution exists.
"Throw them one by one into the Cracks of Doom and watch when Mordor falls!"
Somewhere in a parallel Middle-earth, when Saruman caught Frodo, he only found $n$ rings. And the $i$ -th ring was either gold or silver. For convenience Saruman wrote down a binary string $s$ of $n$ characters, where the $i$ -th character was 0 if the $i$ -th ring was gold, and 1 if it was silver.
Saruman has a magic function $f$ , which takes a binary string and returns a number obtained by converting the string into a binary number and then converting the binary number into a decimal number. For example, $f(001010) = 10, f(111) = 7, f(11011101) = 221$ .
Saruman, however, thinks that the order of the rings plays some important role. He wants to find $2$ pairs of integers $(l_1, r_1), (l_2, r_2)$ , such that:
- $1 \le l_1 \le n$ , $1 \le r_1 \le n$ , $r_1-l_1+1\ge \lfloor \frac{n}{2} \rfloor$
- $1 \le l_2 \le n$ , $1 \le r_2 \le n$ , $r_2-l_2+1\ge \lfloor \frac{n}{2} \rfloor$
- Pairs $(l_1, r_1)$ and $(l_2, r_2)$ are distinct. That is, at least one of $l_1 \neq l_2$ and $r_1 \neq r_2$ must hold.
- Let $t$ be the substring $s[l_1:r_1]$ of $s$ , and $w$ be the substring $s[l_2:r_2]$ of $s$ . Then there exists non-negative integer $k$ , such that $f(t) = f(w) \cdot k$ .
Here substring $s[l:r]$ denotes $s_ls_{l+1}\ldots s_{r-1}s_r$ , and $\lfloor x \rfloor$ denotes rounding the number down to the nearest integer.
Help Saruman solve this problem! It is guaranteed that under the constraints of the problem at least one solution exists.
输入格式
Each test contains multiple test cases.
The first line contains one positive integer $t$ ( $1 \le t \le 10^3$ ), denoting the number of test cases. Description of the test cases follows.
The first line of each test case contains one positive integer $n$ ( $2 \le n \le 2 \cdot 10^4$ ) — length of the string.
The second line of each test case contains a non-empty binary string of length $n$ .
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$ .
The first line contains one positive integer $t$ ( $1 \le t \le 10^3$ ), denoting the number of test cases. Description of the test cases follows.
The first line of each test case contains one positive integer $n$ ( $2 \le n \le 2 \cdot 10^4$ ) — length of the string.
The second line of each test case contains a non-empty binary string of length $n$ .
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$ .
输出格式
For every test case print four integers $l_1$ , $r_1$ , $l_2$ , $r_2$ , which denote the beginning of the first substring, the end of the first substring, the beginning of the second substring, and the end of the second substring, respectively.
If there are multiple solutions, print any.
If there are multiple solutions, print any.
输入输出样例
输入 #1
7 6 101111 9 111000111 8 10000000 5 11011 6 001111 3 101 30 100000000000000100000000000000
输出 #1
3 6 1 3 1 9 4 9 5 8 1 4 1 5 3 5 1 6 2 4 1 2 2 3 1 15 16 30
In the first testcase $f(t) = f(1111) = 15$ , $f(w) = f(101) = 5$ .
In the second testcase $f(t) = f(111000111) = 455$ , $f(w) = f(000111) = 7$ .
In the third testcase $f(t) = f(0000) = 0$ , $f(w) = f(1000) = 8$ .
In the fourth testcase $f(t) = f(11011) = 27$ , $f(w) = f(011) = 3$ .
In the fifth testcase $f(t) = f(001111) = 15$ , $f(w) = f(011) = 3$ .
In the second testcase $f(t) = f(111000111) = 455$ , $f(w) = f(000111) = 7$ .
In the third testcase $f(t) = f(0000) = 0$ , $f(w) = f(1000) = 8$ .
In the fourth testcase $f(t) = f(11011) = 27$ , $f(w) = f(011) = 3$ .
In the fifth testcase $f(t) = f(001111) = 15$ , $f(w) = f(011) = 3$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted