JZOJ 1273. 袁绍的刁难(recruitment.pas/cpp)
程序员文章站
2024-03-17 13:17:34
...
题目:
题意:
求第大的三进制数的组合的和
分析:
一眼正解题(好吧它本来就很水)
直接把转化成二进制,再化成三进制就好了
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<ctime>
#include<iomanip>
#include<string>
#include<bitset>
#include<deque>
#include<set>
#define LL long long
using namespace std;
inline LL read(){
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
LL x[35];
int main()
{
freopen("recruitment.in","r",stdin);
freopen("recruitment.out","w",stdout);
LL q=read();
while(q--)
{
LL n=read();
memset(x,0,sizeof(x));
LL i=0;
while(n)
{
x[++i]=n%2;
n/=2;
}
LL ans=0,k=1;
for(LL j=1;j<=i;j++) ans+=x[j]*k,k*=3;
printf("%lld\n",ans);
}
return 0;
}
上一篇: web前端学习之jquery
下一篇: Python批量修改文件夹下的文件名