C. Rings

题目意思就是第一个   l-r   内二进制转十进制的值大于第二个 l-r

#include "bits/stdc++.h"
 
using namespace std;
int t,n,k;
string s;
int main()
{
    cin >> t;
    while (t--){
        cin >> n >> s;
        int f = s.find('0');   // 判断有无0  有0最好写了
        if(f != -1){
            if(f < n/2){
                //1101111
                //01111
                //1111
                cout << f+1 << " " << n << " " << f+2 << " " << n << endl;
            }else{
                //11101
                //1110   14    
                //111    7
                //因为 0 前面多一位肯定是倍数关系
                cout << 1 << " " << f+1 << " " << 1 << " " << f << endl;
            }
        }else{
            cout << 1 << " " <<  n-1 << " " << 2 <<" " <<  n << endl;
        }
    }
 
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_53013914/article/details/120020559
今日推荐