HDU ACM 1063 Exponentiation 大实数乘方
分析:大实数乘方计算。
#include<iostream>
#include<string>
using namespace std; struct BigReal //高精度实数
{
int len; //长度
int num[10000];
int point; //小数点位置
BigReal()
{
len=1;
point=0;
memset(num,0,sizeof(num));
}
}; bool Read(BigReal& a) //读入一个大实数
{
string s;
int t,i; if(cin>>s)
{
a.len=s.size();
a.point=0;
t=0;
for(i=s.size()-1;i>=0;i--)
{
if(s[i]=='.')
{
a.len--;
a.point=t;
continue;
}
a.num[t++]=s[i]-'0';
}
return true;
}
else
return false;
} void Show(BigReal& a)
{
int i,pos; for(i=0;i<a.point && a.num[i]==0;i++) ;
pos=i;
if(a.point==a.len)
{
if(pos==a.point)
{
cout<<0<<endl; //0.0000000的情况
return ;
}
else
cout<<'.'; //0.121313114的情况
}
for(i=a.len-1;i>=0;i--)
{
cout<<a.num[i];
if(i==pos) break; //小数时后导零不输出
if(i==a.point) cout<<'.';
}
cout<<endl;
} BigReal Mul(const BigReal& a,const BigReal& b)
{
int i,j,len=0;
BigReal c; for(i=0;i<a.len;i++)
for(j=0;j<b.len;j++)
{
c.num[i+j]+=a.num[i]*b.num[j];
if(c.num[i+j]>=10)
{
c.num[i+j+1]+=c.num[i+j]/10;
c.num[i+j]%=10;
}
}
c.point=a.point+b.point;
len=a.len+b.len;
while(c.num[len-1]==0 && len>1&&len>c.point) len--; //处理长度,去掉前导零
if(c.num[len]) len++;
c.len=len;
return c;
} int main()
{
BigReal a;
int b; while(Read(a)&& scanf("%d",&b)==1)
{
BigReal ans;
ans.num[0]=1;
while(b--)
ans=Mul(ans,a);
Show(ans);
}
return 0;
}
HDU ACM 1063 Exponentiation 大实数乘方的更多相关文章
- Exponentiation(java 大实数)
http://acm.hdu.edu.cn/showproblem.php?pid=1063 Exponentiation Time Limit: 2000/500 MS (Java/Others) ...
- hdu acm 1028 数字拆分Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 3533 Escape(大逃亡)
HDU 3533 Escape(大逃亡) /K (Java/Others) Problem Description - 题目描述 The students of the HEU are maneu ...
- hdu acm 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2191 题目意思:有 资金 n 和 m 种类型的大米,对第 i 种类型的大米,价格.数量.袋数分别是: ...
- hdu 1063 Exponentiation
求实数的幂,这个用C++写的话有点长,但是用Java写就非常方便了…… ); System.out.println(an); } }}
- hdu 1063 Exponentiation (高精度小数乘法)
//大数继续,额,要吐了. Problem Description Problems involving the computation of exact values of very large m ...
- hdu 1063 Exponentiation 大数
Problem Description Problems involving the computation of exact values of very large magnitude and p ...
- hdu Exponentiation高精度实数乘幂(用了带小数的高精度模板)
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...
- HDU 1280 前m大的数
http://acm.hdu.edu.cn/showproblem.php?pid=1280 前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory L ...
随机推荐
- HTML5兼容IE各版本的写法
IE下判断IE版本的语句 <!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见 <!--[if lte IE 7]> < ...
- CSS自学笔记(7):CSS定位
很多时候,我们需要对一些元素进行自定义排序.布局等,这是就需要用到CSS的定位属性了,用这些属性对一些元素进行自定义排序.布局等操作,可以改变浏览器默认的死板的排序. CSS定位的功能很容易理解,它允 ...
- 在CMD命令行下关闭进程的命令
转载: [重要]在CMD命令行下关闭进程的命令━━━━━━━━━━━━━━━━━━━━━━━━━━ 方法一: 在"运行"中输入:ntsd -c q -pn 程序名字(在MS-Dos ...
- RejexLib
http://www.regexlib.com/ http://www.brics.dk/automaton/index.html http://code.google.com/p/automatap ...
- 最近招两个兼职的活(PHP和JSP)
我这里的活,都是兼职写作的,是两本入门教程, 一本是PHP+Nginx 一本是JSP+Servlet. 都是入门教程,有署名有稿酬,有兴趣的可以联系 QQ:837652732 验证:PHP或Java ...
- 微信公众号菜单openid 点击菜单即可打开并登录微站
现在大部分微站都通过用户的微信openid来实现自动登录.在我之前的开发中,用户通过点击一个菜单,公众号返回一个图文,用户点击这个图文才可以自动登录微站.但是如果你拥有高级接口,就可以实现点击菜单,打 ...
- 前端工程师须知pc电脑端分辨率
PC端 按屏幕宽度大小排序(主流的用橙色标明) 分辨率 比例 | 设备尺寸 1024*500 (8.9寸) 1024*768 (比例4:3 | 10.4寸.12.1寸.14.1寸.15寸; ) ...
- Codechef Nuclear Reactors 题解
There are K nuclear reactor chambers labelled from 0 to K-1. Particles are bombarded onto chamber 0. ...
- winds引导配置数据文件包含的os项目无效
我装了winds7与linux双系统,用easyBcd程序时,删除了一个winds7,之后winds7就进不去了, 进入winds7时显示winds未能启动,原因可能是最近更改了硬件或软件.解决此问题 ...
- 【Cocos2d TestCpp实例模仿一】-- ActionsTest
转载请注明出处:http://blog.csdn.net/oyangyufu/article/details/25252539 CCActionInterval(持续性动作) 位置性变化动作以To结束 ...