zoukankan      html  css  js  c++  java
  • 按位或 (题目)

    本人水平有限,题解不到为处,请多多谅解

    本蒟蒻谢谢大家观看

    题目大意:在L到R区间范围内,找出一个pps数。

    pps数定义如下:pps数是L到R区间中所有数转成二进制数后,其内含1的个数做多,求这个pps数?

    题目有多组数据

    解法如下:while((L|L+1)<=R)    L=L|L+1;

    最后直接输出L即可

    因为按位或可以保证最多1的个数出现(按位或实质:只要有1,算出来值就为1

    #include<bits/stdc++.h>
    using namespace std;
    int L,R; 
    int t;
    inline int read(){
         int x=0,f=1;
         char ch=getchar();
         while(ch<'0'||ch>'9'){
             if(ch=='-')
                 f=-1;
             ch=getchar();
         }
         while(ch>='0'&&ch<='9'){
             x=(x<<1)+(x<<3)+(ch^48);
             ch=getchar();
         }
         return x*f;
    }
    
    inline void write(int x){
         char F[200];
         int tmp=x>0?x:-x ;
         if(x<0)putchar('-') ;
         int cnt=0 ;
            while(tmp>0)
            {
                F[cnt++]=tmp%10+'0';
                tmp/=10;
            }
            while(cnt>0)putchar(F[--cnt]) ;
    }
    main()
    {
        t=read();
        while(t--)
        {
            L=read();
            R=read();
            while((L|L+1)<=R)
                L=L|L+1;
            write(L);
        }
        return 0;
    }
  • 相关阅读:
    UVA 10056 What is the Probability ?
    Reporting Services Report 带参数
    頁面刷新後,滾動條位置保持不變
    use this as the default and do not ask again
    JQuery Tab 滑动们导航菜单效果
    poj3256
    poj2060
    poj3280
    poj3261
    poj2135
  • 原文地址:https://www.cnblogs.com/nlyzl/p/11283031.html
Copyright © 2011-2022 走看看