博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1001 Exponentiation
阅读量:6710 次
发布时间:2019-06-25

本文共 1814 字,大约阅读时间需要 6 分钟。

给出一个实数x和一个整数n

求x^n

这是一道高精度题,把实数转化为整数后解决,处理小数点位置即可

(破题写了一上午)

#include
#include
#include
#include
using namespace std;const int N=1e5+5;struct name{ int s[N],l; name(){memset(s,0,sizeof(s));} void push() { int ll=l; for(int i=0;i<2*ll;i++) { s[i+1]+=s[i]/10; s[i]%=10; if(s[i]!=0) l=max(l,i); } } void pushup(int x) { s[x+1]+=s[x]/10; s[x]%=10; if(s[x+1]!=0) l=max(l,x+1); if(s[x]!=0) l=max(l,x); } friend inline name operator *(const name &x,const name &y) { name ret; int l1=x.l,l2=y.l; // for(int i=l1-1;i>=0;i--) printf("%d",x.s[i]);putchar('*'); // for(int i=l2-1;i>=0;i--) printf("%d",y.s[i]);putchar('='); ret.l=l1+l2; for(int i=0;i
=0;i--) printf("%d",ret.s[i]);putchar('\n'); return ret; }}a,ans;name qpow(name x,int y){ name ret=x;y--; while(y) { if(y&1) ret=ret*x; x=x*x; y>>=1; } return ret;}char str[N],S[N];int n;int main(){ while(~scanf("%s%d",str,&n)) { int l=strlen(str),pos=-1; a.l=0; for(int i=l-1,j=0;i>=0;i--,j++) { if(str[i]=='.') { pos=j; continue; } a.s[a.l++]=str[i]-'0'; } ans=qpow(a,n); l=ans.l; //printf("Y%dY\n",pos); pos=pos*n; //printf("Z%dZ\n",pos); int st=0,ed=-1; for(int i=l-1,j=0;i>=0;i--,j++) { if(i==pos-1)S[++ed]='.'; S[++ed]=ans.s[i]+'0'; //printf("%d",ans.s[i]); } //putchar('\n'); while(S[st]=='0') st++; if(pos!=-1)while(S[ed]=='0') ed--; if(S[ed]=='.')ed--; if(st>ed) putchar('0'); for(int i=st;i<=ed;i++) printf("%c",S[i]); putchar('\n'); } return 0;}

 

转载于:https://www.cnblogs.com/pigba/p/8984775.html

你可能感兴趣的文章
JavaScript引擎V8 5.1遵循了更多的ECMAScript规范并支持WASM
查看>>
广度、深度、易用性,详解6大机器学习云
查看>>
雇佣和留住开发人员,打造优秀的团队
查看>>
关于5G被激烈讨论的那些争端和冲突
查看>>
vuejs 检视组件结构
查看>>
LeetCode 14_Longest Common Prefix
查看>>
年终总结,程序员票选最喜欢的编程语言花落谁家?
查看>>
linux基础命令介绍六:网络
查看>>
npm 企业版 npm Enterprise 正式发布,主打安全性
查看>>
Jenkins部署码云SpringBoot项目
查看>>
理解alivc_framework 状态机
查看>>
性能优化技巧 - 程序游标
查看>>
简单介绍 Swift on Fedora —— 在 Fedora 中使用 Swift
查看>>
在SpringAOP中如何获取方法的参数值(实体类)以及参数名
查看>>
Charles安装和抓包
查看>>
Java数据结构与算法(五)-双向链表
查看>>
抛弃NVelocity,来玩玩Razor
查看>>
在JavaScript面向对象编程中使用继承(1)
查看>>
高铁与机场成交通信息化建设的双驾马车
查看>>
遇到问题描述:Android Please ensure that adb is correctly located at问题解决
查看>>