计算机学院大学生程序设计竞赛(2015’12) 1005 Bitwise Equations

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn=120;
long long X,K;
long long  basex[maxn];
long long basek[maxn];
int totx,totk;

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld%lld",&X,&K);

        totx=totk=0;
        memset(basex,0,sizeof basex);
        memset(basek,0,sizeof basek);

        while(X)
        {
            basex[totx++]=X%2;
            X=X/2;
        }
        while(K)
        {
            basek[totk++]=K%2;
            K=K/2;
        }

        int now=0;
        for(int i=0;i<totk;i++)
        {
            for(int j=now;;j++)
            {
                if(basex[j]==0)
                {
                    basex[j]=basek[i];
                    now=j+1;
                    break;
                }
                else
                {
                    basex[j]=0;
                    now=j+1;
                }
            }
        }
        for(int i=now;i<=100;i++)
            if(basex[i]==1) basex[i]=0;

        long long ans=0;
        for(int i=0;i<=100;i++) ans=ans+(long long)(basex[i]*pow(2.0,i));
        printf("%lld\n",ans);
    }
    return 0;
}
时间: 2024-12-24 12:39:03

计算机学院大学生程序设计竞赛(2015’12) 1005 Bitwise Equations的相关文章

hdu 计算机学院大学生程序设计竞赛(2015’11)

搬砖 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 5134    Accepted Submission(s): 1288 Problem Description 小明现在是人见人爱,花见花开的高富帅,整天沉浸在美女环绕的笙歌妙舞当中.但是人们有所不知,春风得意的小明也曾有着一段艰苦的奋斗史. 那时的小明还没剪去长发,没有信用卡没有她

HDU计算机学院大学生程序设计竞赛(2015’12)1005 Bitwise Equations

题意:已知x,k 求第k个使得x+y==x|y的正整数y x+y==x|y 即x为1的位y为0 可知y有几位可以为1 详见代码 #include<cstdio> #include<cstring> #include<string> #include<iostream> #include<algorithm> #include<map> using namespace std; const int N=50005; int n,k; i

HDU计算机学院大学生程序设计竞赛(2015’12)1006 01 Matrix

题意: 有一个n*n(n<=1000)的01矩阵 Q次询问(1000) 每次询问有几个大于等于k的全为一的子矩形 从右下角往右上角预处理每个点有一个r x vr代表右边有多少连续1x代表下面有多少连续1v代表以这个为左上角的矩阵最大是多少所以v[i][j]= min(r[i][j+1], x[i+1][j],v[i+1][j+1]) +1 r[i][j]=r[i][j+1]+1; x[i][j]=x[i+1][j]+1; 然后ans[v[i][j]]++ 预处理后缀和  O 1 输出 #incl

HDU计算机学院大学生程序设计竞赛(2015’12)Happy Value

Happy Value Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1453    Accepted Submission(s): 428 Problem Description In an apartment, there are N residents. The Internet Service Provider (ISP) wa

HDU计算机学院大学生程序设计竞赛(2015’12)The Country List

The Country List Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2598    Accepted Submission(s): 615 Problem Description As the 2010 World Expo hosted by Shanghai is coming, CC is very honorable

计算机学院大学生程序设计竞赛(2015’12)The collector’s puzzle

Problem Description There is a collector who own many valuable jewels. He has a problem about how to store them. There are M special boxes. Each box has a value. And each of the N jewels has a value too. The collector wants to store every jewel in on

计算机学院大学生程序设计竞赛(2015’12) 1003 The collector’s puzzle

#include<cstdio> #include<algorithm> using namespace std; using namespace std; const int maxn=100000+10; int a[maxn],b[maxn]; int main() { int n,m; while(scanf("%d %d",&n,&m)!=EOF) { for(int i=1; i<=n; i++) scanf("%d&

计算机学院大学生程序设计竞赛(2015’12) 1002 Polygon

#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; struct Point { double x; double y; } p[1001], px[10001]; int n; double eps=1e-8; int cmp(Point a, Point b) { if(ab

计算机学院大学生程序设计竞赛(2015’12) 1001 The Country List

#include<cstdio> #include<cstring> #include<cmath> #include<string> #include<vector> #include<map> #include<algorithm> using namespace std; char s[100+10][20+10]; int n; map<string ,int>m; int main() { while