poj1001 2010.2.25
来源:互联网 发布:浙江网络诈骗立案标准 编辑:程序博客网 时间:2024/05/21 22:39
poj1001 2010.2.25
思路:
高精度乘法,忽略掉小数点,最后再点上,小数的位数,就是R的小数位数*n
#include <stdio.h>#include <string.h>#define N 10000#define M 15char s[M],mid[M];int num[N],ans[N],temp[N];int n,point,goal,ls,lnum,lans,ltemp;void change(){ls=strlen(s);ls--;int i;while (s[ls]=='0')ls--;int ls2=ls;point=0;while (s[ls2]!='.'){point++;ls2--;}lnum=0;memset(num,0,sizeof(num));for(i=ls;i>=0;i--)if (s[i]!='.'){lnum++;num[lnum]=s[i]-48;}goal=point*n;}void cal(){ lans=lnum; int i,j,k; memcpy(ans,num,sizeof(num)); for(k=1;k<n;k++) {memset(temp,0,sizeof(temp));for(i=1;i<=lnum;i++)for(j=1;j<=lans;j++){temp[i+j-1]+=num[i]*ans[j];temp[i+j]+=temp[i+j-1]/10;temp[i+j-1]%=10;}ltemp=lans+lnum-1;while(temp[ltemp+1]){temp[ltemp+1]+=temp[ltemp]/10;temp[ltemp]%=10;ltemp++;}memcpy(ans,temp,sizeof(temp));lans=ltemp; }// for(i=lans;i>=1;i--)// printf("%d",ans[i]);// printf("\n");}void out(){int i;while (ans[lans]==0)lans--;if (lans<=goal){printf(".");for(i=goal;i>=1;i--)printf("%d",ans[i]);}else{for(i=lans;i>goal;i--)printf("%d",ans[i]);if (goal!=0) printf(".");for(i=goal;i>=1;i--)printf("%d",ans[i]);}printf("\n");}void main(){while (scanf("%s %d",s,&n)!=EOF){//printf("-----%s----%d-----\n",s,n);change();cal();out();}}
0 0
- poj1001 2010.2.25
- POJ1001
- poj1001
- poj1001
- POJ1001
- POJ1001
- poj1001
- POJ1001
- poj1001
- POJ1001
- POJ1001
- poj1001
- POJ1001
- POJ1001
- poj1001
- POJ1001
- POJ1001
- POJ1001
- Verify Preorder Serialization of a Binary Tree
- UML:统一建模语言
- 使用SecureCRT在windows与linux间传输文件
- hdu2817 2010.2.25
- [Unity3D]Window Phone代码通信
- poj1001 2010.2.25
- hdu2824 2010.2.26
- L2 正则化
- poj2926 2010.2.26
- Java设计模式(十八)----命令模式
- hdu3220 2010.3.1
- HDU 3639 Hawk-and-Chicken(强连通分量+缩点)
- XStream的使用(2)——集合形式的 JavaBean 转化为 xml
- HYSBZ/BZOJ 1037 [ZJOI2008] 生日聚会Party - dp