2019.01.27【NOIP提高组】模拟B组 JZOJ 1273 袁绍的刁难
作者:互联网
Description
选第i个武将的价值是3i−1,求第k大的代价
Solution
进制转换题,不想多说。
Code
#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