C. Rings
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard outputFrodo 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 nn rings. And the ii-th ring was either gold or silver. For convenience Saruman wrote down a binary string ss of nn characters, where the ii-th character was 0 if the ii-th ring was gold, and 1 if it was silver.
Saruman has a magic function ff, 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)=221f(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 22 pairs of integers (l1,r1),(l2,r2)(l1,r1),(l2,r2), such that:
Here substring s[l:r]s[l:r] denotes slsl+1…sr−1srslsl+1…sr−1sr, and ⌊x⌋⌊x⌋ 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.
Input
Each test contains multiple test cases.
The first line contains one positive integer tt (1≤t≤1031≤t≤103), denoting the number of test cases. Description of the test cases follows.
The first line of each test case contains one positive integer nn (2≤n≤2⋅1042≤n≤2⋅104) — length of the string.
The second line of each test case contains a non-empty binary string of length nn.
It is guaranteed that the sum of nn over all test cases does not exceed 105105.
Output
For every test case print four integers l1l1, r1r1, l2l2, r2r2, 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.
Example
input
Copy
7 6 101111 9 111000111 8 10000000 5 11011 6 001111 3 101 30 100000000000000100000000000000
output
Copy
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
Note
In the first testcase f(t)=f(1111)=15f(t)=f(1111)=15, f(w)=f(101)=5f(w)=f(101)=5.
In the second testcase f(t)=f(111000111)=455f(t)=f(111000111)=455, f(w)=f(000111)=7f(w)=f(000111)=7.
In the third testcase f(t)=f(0000)=0f(t)=f(0000)=0, f(w)=f(1000)=8f(w)=f(1000)=8.
In the fourth testcase f(t)=f(11011)=27f(t)=f(11011)=27, f(w)=f(011)=3f(w)=f(011)=3.
In the fifth testcase f(t)=f(001111)=15f(t)=f(001111)=15, f(w)=f(011)=3f(w)=f(011)=3.
=========================================================================
首先全是1肯定是满足的,选择1-n-1 2-n大小相等
然后我们注意到0的位置可能在1--n/2
n/2+1 --n
一旦在1--n/2,那么该位置 p--n p+1--n是一定相等且长度都满足要求的
如果在n/2+1 --- n 那么 1-p 1-p-1是二倍的关系 (二进制后面添加0会扩大二倍,也称为整体左移一位,是 <<运算 )
所以一定是能够满足的
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- using namespace std;
-
-
- int main()
- {
-
- int t;
-
- cin>>t;
-
- while(t--)
- {
- int n;
-
- cin>>n;
-
- string s;
-
- cin>>s;
- // 0 1 2 3 4
-
- //0 1 2 3
-
- //0 1 2
-
- //0 1
-
- int flag=0;
-
- s=" "+s;
-
- for(int i=1;i<=n;i++)
- {
- if(s[i]=='0')
- {
-
- if(i>n/2)
- {
- cout<<1<<" "<" "<<1<<" "<-1<
-
- flag=1;
-
- break;
- }
- else
- {
- cout<" "<
" "<1<<" "< -
- flag=1;
-
- break;
- }
- }
- }
-
- if(!flag)
- {
- cout<<1<<" "<
-1<<" "<<2<<" "< - }
- }
- return 0;
- }
-
相关阅读:
银行招聘问题集锦
我对需求分析的理解
C. Zero-Sum Prefixes Codeforces Round #833 (Div. 2)(前缀和+贪心)
GFS分布式文件系统&实验
【Microelectronic Systems】
Layui数据表格中checkbox位置不居中
P14 JDBC 快速入门
基于工程车辆/物流车辆/消防车辆远程通信的车队管理解决方案
Linux 下以其他用户运行程序
xctf攻防世界 Web高手进阶区 webshell
-
原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126173546
-
最新文章
-
沪漂五周年了:我越来越迷茫了
Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
MySQL-Seconds_behind_master的精度误差
[MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
Agent OS :五种驯服不确定性的范式
PortSwigger SQL注入LAB11
数据库即时编译JIT
[Begin]AI Learn Data Day 0
深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU