范围查询(位操作) [英] Range queries(bit manipulation)

查看:88
本文介绍了范围查询(位操作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://practice.geeksforgeeks.org/contest-problem/sp-range-queries/0/

以上是该问题的链接。



我尝试了什么:



我只能得到问题的强力方法。但由于限制很高。我得到了预期的TLE。

https://practice.geeksforgeeks.org/contest-problem/sp-range-queries/0/
above is the link for the question.

What I have tried:

I could only get the brute force method for the question. But since the limit are pretty high..i got a TLE as expected.

推荐答案

这是一场比赛:所以你在这里要求解决方案是作弊,我们不要帮助。



想法是你怜惜 你的 大脑和 你的 技能对抗其他参赛者,而不是我的。
It's a contest: so your asking for a solution here is cheating, and we don't help with that.

The idea is that you pity your brain and your skills against other entrants, not mine.


与其他任何挑战一样的挑战是测试你的能力,你的编程技巧。

This challenge like any other challenges is to test your ability, you skills at programming.
Quote:

我只能得到问题的强力方法。

I could only get the brute force method for the question.



蛮力有不同的等级。你应该展示你的代码。



在'geeksforgeeks.org'上,挑战非常困难,只有你对算法和数据结构的了解才能帮助你。



一般来说,蛮力是第一个找到的解决方案,然后研究有用的和可以删除的是导致更好的解决方案。


There is different levels in brute force. You should show your code.

On 'geeksforgeeks.org', challenges are notoriously difficult and only your knowledge of algorithms and data structures can help you.

Generally speaking, brute force is the first solution one find, then a study of what is useful and what can be removed is the lead to a better solution.


这是我的暴力逻辑

This is my brute force logic
//
// Created by B Sriman on 10-07-2018.
//

#include <iostream>
using namespace std;

int main() {
    //code
    int t;
    cin>>t;
    while(t--){
        int q;
        cin>>q;
        while(q--){
            int l,r;
            cin>>l>>r;
            int total_count = 0;
            for(int i=l;i<=r;i++){
                int count = 0;
                int j = i;
                while(j){
                    j &= j-1;
                    count++;
                }
                if(count <= 3)
                    total_count++;
            }

            cout<<total_count<<endl;
        }
    }
    return 0;
}


这篇关于范围查询(位操作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆