其他分享
首页 > 其他分享> > 2019.01.27【NOIP提高组】模拟B组 JZOJ 1273 袁绍的刁难

2019.01.27【NOIP提高组】模拟B组 JZOJ 1273 袁绍的刁难

作者:互联网

DescriptionDescriptionDescription

选第iii个武将的价值是3i13^{i-1}3i−1,求第kkk大的代价


SolutionSolutionSolution

进制转换题,不想多说。


CodeCodeCode

#include<cstdio>
using namespace std;long long power[35],k,ans,j;
int n;
signed main()
{
	freopen("recruitment.in","r",stdin);
	freopen("recruitment.out","w",stdout);
	power[0]=1;
	for(register int i=1;i<33;i++) power[i]=power[~-i]+(power[~-i]<<1);//预处理3的任意次方
	scanf("%d",&n);
	while(n--)
	{
		scanf("%lld",&k);
		j=0;ans=0;
		while(k)
		{
			if(k&1) ans+=power[j];
			k>>=1;j++;
		}
		printf("%lld\n",ans);
	}
}

标签:27,power,NOIP,JZOJ,int,long,recruitment,3i,ans
来源: https://blog.csdn.net/xuxiayang/article/details/86666786