• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ACM s1124yy
守りたいものが 強くさせること
博客园    首页    新随笔    联系   管理     

BestCoder Round #84 Aaronson

Aaronson

题意:

给个中文链接:戳戳戳

题解:

这题一看给的公式就是二进制,之后马上就能想到当m大于等于二进制的位数时,输出n的二进制的1的个数就好了。之后就是m小于二进制的位数时,只要加上2的(总位数-m)次方就好了,当且仅当这一位是1的时候成立。

代码:

include

include

include

include

using namespace std;

const int INF=0x3f3f3f3f;
typedef long long ll;
#define PU puts("");
#define PI(A) printf("%d\n",A)
#define SI(N) scanf("%d",&(N))
#define SII(N,M) scanf("%d%d",&(N),&(M))
#define cle(a,val) memset(a,(val),sizeof(a))
#define rep(i,b) for(int i=0;i<(b);i++)
#define Rep(i,a,b) for(int i=(a);i<=(b);i++)
#define reRep(i,a,b) for(int i=(a);i>=(b);i--)
const double EPS= 1e-9 ;

/* ///////////////////////// C o d i n g S p a c e ///////////////////////// */

const int MAXN= 1000 + 9 ;

int main()
{
int o;
SI(o);
while(o--)
{
int a,b;
SII(a,b);
int c=a;
int cnt=-1,cnt1=0;
while(c)
{
if (c&1) cnt1++;
cnt++;
c>>=1;
}
if (cnt<=b) PI(cnt1);
else
{
c=a;
int ct=0,ct1=0;
int ans=0;
while(c)
{
if (c&1)
{
if (ct<=b)
{
ans++;
}
else
{
ans=ans+(int)pow(2.0,ct-b);
}
}
ct++;
c>>=1;
}
PI(ans);
}
}
return 0;
}

posted @ 2016-07-24 09:51  s1124yy  阅读(126)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3