【老李的模拟赛】【#2】【2014-08-07】

老孔监考欢乐多~

题目+数据:http://pan.baidu.com/s/1o61B4dc

T1:

感觉比较适合做CF的B,不错的贪心 AC

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
LL getone(LL x){
	LL ans=0;
	for(;x;x-=x&-x)ans++;
	return ans;
}
LL getlen(LL x){
	LL len=0;
	for(;x;x>>=1)len++;
	return len;
}
int main(){
	freopen("water.in","r",stdin);
	freopen("water.out","w",stdout);
	LL n,k;
	cin>>n>>k;
	if(n<=k||!n||getone(n)<=k){puts("0");return 0;}
	LL tot=0,len=getlen(n),ans=1<<30;
	LL test=n;
	while(getone(test)>k){
		test-=test&-test;
		test=test-(test&-test)+((test&-test)<<1);
	}cout<<test-n<<endl;
	
	return 0;
}

T2:理解错题意…… 0

T3:打了个6M的表…… 40

T4又是一个贪心…… AC


你可能感兴趣的:(省选)