A | Groundhog and 2-Power Representation |
题意:给定一个式子,括号代表次幂级,只可能是2的次幂。
不会python的本菜鸡用了栈,很难写明白,最后失败了。
(体会到了python库的强大
def T(x):
return pow(2,x)
s=input()
s=s.replace('2(','T(')
print(eval(s))
I | The Crime-solving Plan of Groundhog |
题意:给定一个数组,随机组成两个数字a,b,求其最大的乘机m。因为数据范围,数组长度在1e6,所以需要用到字符串存数,并且进行高精度相乘。
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1234567;
typedef long long ll;
ll t,n,a[maxn];
string s,c;
string mul(string a,ll m){
string c="";
ll tt=0;
// cout<<tt<<endl;
for(int i = a.size()-1;i>=0 || tt;i--){
//cout<<i<<endl;
if(i>=0) tt += (a[i]-'0')*m;
c+= (char)((tt%10) +'0');
tt/=10;
}
reverse(c.begin(),c.end());
return c;
}
int main()
{
cin>>t;
while(t--){
s.clear();
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
ll i=0,m;
while(1){
if(a[i]!=0){
m=a[i];
break;
}
i++;
}
i++;
ll k=i-1;
s+=(char)(a[i]+'0');
i++;
while(k--) s+=(char)('0');
while(i<n){
s+=(char)(a[i]+'0');
i++;
}
//cout<<s<<endl;
cout<<mul(s,m)<<endl;
}
return 0;
}