| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
终于AC……帖一波#include <cstdio>
#include <cstring>
const int maxsize = 3001;
int mult(short* a, short* b, int n, int m, short* result) {
int i,j;
for(i=0;i<n;i++){
for(j=0;j<m;j++){result[i+j]+=a[i]*b[j];
result[i+j+1]+=result[i+j]/10;result[i+j]=result[i+j]%10;}
}
return i+j;
}
int pow(short* a, int size, int n, short* result) {
if (n==1){memcpy(result,a,size*2);return size;}
short t[maxsize];int len,m;m=len=size;memcpy(t, a, size*2);
for (int ii=0;ii<n-1;ii++){memset(result, 0, len*2);
len=mult(t,a,len,m,result);memcpy(t, result, len*2);}
return len;
}
int main() {
char a[10];int n,p=6,cur=0,len;short b[5],c[maxsize];
while(scanf("%s %d",&a,&n)!=EOF) {
p=6; cur=0; memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); while (a[--p]=='0');
for(int i=p;i>-1;i--){if(a[i]=='.'){p=(p-i)*n;continue;}b[cur++]=a[i]-'0';}
len=pow(b,5,n,c); while(c[--len]==0); cur=++len; if(p>=len){printf(".");cur=p;}
while(--cur>-1){if(cur<len) printf("%d",c[cur]); else printf("0");
if(cur==p && cur>0) printf(".");} printf("\n");}
return 0;
}
内存340K,虽然速度还行……以及这题输入是真的好坑啊,当初应该就是被0000.1和0001.0卡WA的。
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator