JZOJ 1273. 袁绍的刁难
题目
分析
就是把转成3进制输出就好了
代码
1 #include<iostream> 2 #define ll long long 3 //#define cin fin 4 //#define cout fout 5 using namespace std; 6 //ifstream fin("recruitment.in"); 7 //ofstream fout("recruitment.out"); 8 ll a[101]; 9 void take() 10 { 11 a[1]=1; 12 for (int i=2;i<=100;i++) 13 a[i]=a[i-1]*3; 14 } 15 string fun(ll k) 16 { 17 string s=""; 18 while (k!=0) 19 { 20 s+=(k%2)+'0'; 21 k/=2; 22 } 23 return s; 24 } 25 int main () 26 { 27 ios::sync_with_stdio(false); 28 ll T,k,ans; 29 string ss; 30 cin>>T; 31 take(); 32 for (int i=1;i<=T;i++) 33 { 34 cin>>k; 35 ans=0; 36 ss=fun(k); 37 for (int i=0;i<ss.size();i++) 38 { 39 if (ss[i]=='1') 40 ans+=a[i+1]; 41 } 42 cout<<ans<<endl; 43 } 44 //fin.close(); 45 //fout.close(); 46 }
为何要逼自己长大,去闯不该闯的荒唐