位运算不会怎末办 ???那就暴力呀!!!!
#include<iostream>
#include<cmath>
#include<set>
#include<algorithm>
#include<string>
#include<map>
#include<cstdio>
#define ll long long
#define x firdt
#define y second
#define met(a,b) memset(a,b,sizeof a)
#define inf 0x3f3f3f3f
using namespace std;
const int N=1e6+10;
const int mod=1e9+7;
int j;
int dd(int a[]) {
int sum=0;
for(int i=0; i<j; i++) {
if(a[i]==2) {
a[i]=0;
a[i+1]++;
}
}
for(int i=j-1; i>=0; i--) sum=sum*2+a[i];
return sum;
}
int main() {
int n,t;
while(~scanf("%d%d",&n,&t)) {
int a[35]= {0};
j=0;
while(n) {
a[j++]=n%2;
n/=2;
}
j=34;
while(t--) {
int x,y;
scanf("%d%d",&x,&y);
x--;
if(a[x]==0) {
printf("%d\n",dd(a));
continue;
}
a[x]=0;
if(a[x+y]==0) {
a[x+y]=1;
} else a[x+y]+=1;
printf("%d\n",dd(a));
}
}
}
题目描述
小T在上网冲浪时发现了一组操作序列,潜意识告诉他根据上面的信息操作会有意向不到的事情发生。
操作规则是,对于一个数N,将其二进制下的某一位的1移动至另一个位置,如果原位置不为1则忽略,如果目标位置原先也为1,则进位。依次操作改变N的值。
输入
本题为多样例测试。
首行输入两个整数N、T,分别代表原始数字和样例数,0 < N < 1e9,T 不超过100000。
下面T行,每行输入两个整数x、y,代表将第x位向左移y位,0<x<31,-x<y<31 - x。
输出
对于每次操作,输出操作后的数,单独占一行,题目保证答案不会超出int范围。
样例输入
75 3 7 -4 4 -3 4 7
样例输出
15 8 1024