Description

Problems involving the computation of exact values of very large magnitude and precision are common. For example,the computation of the national debt is a taxing experience for many computer systems.

This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.

Input

The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6,and the n value will be in columns 8 and 9.

Output

The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.

Sample Input

95.123 12

0.4321 20

5.1234 15

6.7592 9

98.999 10

1.0100 12

Sample Output

548815620517731830194541.899025343415715973535967221869852721

.00000005148554641076956121994511276767154838481760200726351203835429763013462401

43992025569.928573701266488041146654993318703707511666295476720493953024

29448126.764121021618164430206909037173276672

90429072743629540498.107596019456651774561044010001

1.126825030131969720661201

本题代码poj上过了,hdu上过不了,不想再调了

这种题感觉没有什么算法可言,Java处理会好很多。主要是各种处理很烦 ,写上来主要纪念一下

AC代码:

# include <cstdio>
# include <cstring>
using namespace std;
char g_s[10];
int s1[200],s2[10],n;
int judge(){
	int n=0;
	for(int i=0; i<=5; i++){
		if(g_s[i]=='0'){
			n++;
		}
	}
	if(n>=5)
	return 1;
	return 0;
}
int cal_bit(){
	int sum,cnt=0;
	int i=5;
	while(g_s[i]=='0'){
		i--;
	}
	for( ; i>=1; i--){
		if(g_s[i]=='.'){
			return cnt;
		}
		else{
			cnt++;
		}
	}
	return 0;
}

void cal_ch(){
	int i=0,j=5,k;
	int cnt=0;
	while(g_s[i]=='.'||g_s[i]=='0'){
		i++;
	}
	while(g_s[j]=='0'){
		j--;
	}
	for(k=j; k>=i; k--){
		if(g_s[k]=='.'){
			continue;
		}
		else{
			s1[cnt]=g_s[k]-'0';
			s2[cnt]=g_s[k]-'0';
			cnt++;
		}
	}
}

void cal_ans(){
	int i,j,k;
	int end1=199,end2=9;
	int temp[200];
	memset(temp,sizeof(temp));
	while(s1[end1]==0){
		end1--;
	}
	while(s2[end2]==0){
		end2--;
	}
	for(i=0; i<=end2; i++){
		for(k=0; k<=end1; k++){
			temp[i+k]=temp[i+k]+s1[k]*s2[i];
		}
	}
    int c=0;
    for(i=0; i<199; i++){
    	temp[i]=temp[i]+c;
    	c=temp[i]/10;
    	temp[i]=temp[i]%10;
	}
	for(i=0; i<200; i++){
		s1[i]=temp[i];
	}

}

int main(){
	int bits,i,k;
	int ans[400];
	while(scanf("%s %d",g_s,&n)!=EOF){
		getchar();		
		if(n==0) {
			printf("1\n");
			continue;
		}
		if(judge()){
			printf("0\n");
			continue;
		}
		memset(s1,sizeof(s1));
		memset(s2,sizeof(s2));
		cal_ch();
		bits=cal_bit();
		for(i=1; i<n; i++){
			cal_ans();
		}
		bits=bits*n;
		if(bits){
			memset(ans,sizeof(ans));
			int cnt;
			for(i=199; i>=0;){
				if(s1[i]==0){
					i--;
				}
				else{
					break;
				}
			}
			j=200;
			for(; i>=0; i--){
				ans[j++]=s1[i];
			}
			cnt=j-bits;
			for(k=0; k<cnt; ){
				if(ans[k]==0){
					k++;
				}
				else{
					break;
				}
			}
			if(!(k==cnt-1&&ans[k]==0)){
				for( ; k<cnt; k++){
					printf("%d",ans[k]);				
				}
			}
			j--;
			for(; j>=cnt; ){
				if(ans[i]==0){
					j--;
				}
				else{
					break;
				}
			}
			for(k=cnt; k<=j; k++){
				if(k==cnt){
					printf(".");
				}
				printf("%d",ans[k]);
			}
			printf("\n");
		}
		else{
			for(i=199; i>=0; ){
				if(s1[i]==0){
					i--;
				}
				else{
					break;
				}
			}
			for(j=i; j>=0; j--){
				printf("%d",s1[j]);
			}
		   printf("\n");
		}
	}
	return 0;
}

dawei

【声明】:北京站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。