计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations
Bitwise Equations
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 633 Accepted Submission(s): 335
Where '|' denotes the bitwise OR operator.
For each case, there are two integers X and K (1 <= X, K <= 2000000000) in one line.
3
5 1
5 5
2000000000 2000000000
2
18
16383165351936
总是望着曾经的空间发呆,那些说好不分开的朋友不在了,转身,陌路。 熟悉的,安静了, 安静的,离开了, 离开的,陌生了, 陌生的,消失了, 消失的,陌路了。
#include <string.h>
#include <iostream>
using namespace std;
long long rets=0;
class jisuan
{
public:
long long kthPlusOrSolution(int, int);
string getBin(int);
};
string jisuan::getBin(int x)
{
string ret="";
if(x==0)
{
ret="0";
return ret;
}
while(x>0)
{
ret=char(x%2+'0')+ret;
x/=2;
}
return ret;
}
long long jisuan::kthPlusOrSolution(int x, int k)
{
string strx, strk;
strx=getBin(x);
strk=getBin(k);
int lx=strx.length()-1;
int lk=strk.length()-1;
string ret="";
while(lx>=0 && lk>=0)
{
if(strx[lx]=='1')
{
ret="0"+ret;
--lx;
}
else
{
ret=strk[lk]+ret;
--lx;
--lk;
}
}
while(lk>=0)
ret=strk[lk--]+ret;
for(int i=0;i<(int)ret.length();i++)
rets=(rets<<1)+ret[i]-'0';
return rets;
}
int main()
{
int n,x,k;
jisuan bit;
cin>>n;
while(n--)
{
rets=0;
cin>>x>>k;
bit.kthPlusOrSolution(x,k);
cout<<rets<<endl;
}
}
@执念 "@☆但求“❤”安★
下次我们做的一定会更好。。。。
为什么这次的题目是英文的。。。。QAQ...
计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations的更多相关文章
- hdu 计算机学院大学生程序设计竞赛(2015’11)
搬砖 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submissi ...
- 计算机学院大学生程序设计竞赛(2015’11)1005 ACM组队安排
1005 ACM组队安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- 计算机学院大学生程序设计竞赛(2015’12) 1005 Bitwise Equations
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...
- 计算机学院大学生程序设计竞赛(2015’12)Study Words
Study Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 计算机学院大学生程序设计竞赛(2015’12)Polygon
Polygon Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- 计算机学院大学生程序设计竞赛(2015’12)The Country List
The Country List Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 计算机学院大学生程序设计竞赛(2015’12) 1008 Study Words
#include<cstdio> #include<cstring> #include<map> #include<string> #include&l ...
- 计算机学院大学生程序设计竞赛(2015’12) 1009 The Magic Tower
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...
- 计算机学院大学生程序设计竞赛(2015’12) 1006 01 Matrix
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> ...
随机推荐
- SpringBoot + Spring Security 基本使用及个性化登录配置详解
Spring Security 基本介绍 这里就不对Spring Security进行过多的介绍了,具体的可以参考官方文档 我就只说下SpringSecurity核心功能: 认证(你是谁) 授权(你能 ...
- [转]UITableView全面解析
转自:http://www.cnblogs.com/kenshincui/p/3931948.html#mvc 概述 在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软 ...
- jstl 标签 的应用
参考文档:http://www.yiibai.com/jsp/jstl_core_choose_tag.html 1.jstl中foreach序号 <c:forEach items=" ...
- Struts2防止重复提交
一般使用<interceptor-ref name="token"></interceptor-ref>或者<interceptor-ref name ...
- linux find grep 查找命令
原文:fhqdddddd.blog.163.com/blog/static/186991542012417105729415/ find 1.作用 find命令的作用是在目录中搜索文件,它的使用权限是 ...
- 春哥的nginx systemtap调试脚本简单介绍
http://card.weibo.com/article/h5/s#cid=2304185311ad2d0102v9gd&vid=0&extparam=&from=11100 ...
- iOS中创建自定义的圆角按钮
iOS中很多时候都需要用到指定风格的圆角按钮,尽管UIButton提供了一个方式创建圆角按钮: + (id)buttonWithType:(UIButtonType)buttonType;//指定bu ...
- 关于android分享(sharedsdk的简单使用)
老早就使用了.可是如今才写,惰性太大,如今改 如今做产品的话相信大家基本都做分享吧.一个是项目的需求须要,另一个是能够非常好的宣传自己的产品.其它的优点依据情况而论 事实上每一个平台都有它自己的文档, ...
- Linux常用C函数-接口处理篇(网络通信函数)
接口处理篇accept,bind,connect,endprotoent,endservent,getsockopt,htonl,htons,inet_addr,inet_aton,inet_ntoa ...
- chrome 的onbeforeunload事件没有触发
onbeforeunload event is not working when user not click inside the body of page 0down votefavorite ...