Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:终于AC……帖一波

Posted by klbertj at 2018-11-24 23:43:55 on Problem 1001
In Reply To:终于AC……帖一波 Posted by:KAAAsS at 2017-03-11 22:09:49
> #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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator