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 ...
随机推荐
- sqlserver 分页sql语句
select * from (select *,row_number() over(order by CONTENT_ID ) as rnum from ArchiveContents) t whe ...
- IP校验和
#include <stdio.h> #include <unistd.h> #include <linux/if_ether.h> #include <li ...
- SendMessage基本认识
SendMessage基本认识 函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.而函数PostMessage不同,将一个消息寄送到一个线 ...
- 自写的LastPos,寻找字符串里的最后一个字符,RTL里没有提供这个函数——Delphi的String下标是从1开始的
已经好几次了,没有这个函数还是感觉很不方便,所以自己写了一个: function LastPos(strFind :string; ch: Char): integer; var i, n: inte ...
- Saiku国际化总结
国际化步骤: 1.在mondrian.properties同路径下加上locale_zh_CN.properties资源文件,内容例如:schema.name.K12UserAnalysis=K12用 ...
- linux下Oracle11g RAC搭建(六)
linux下Oracle11g RAC搭建(六) 五.校验安装前的环境 root身份下完毕解压grid.database安装包 [grid@node1 soft]$ su - Password: [r ...
- 2014 Web开发趋势
本文翻译自:http://www.pixelstech.net/article/1401629232-Web-design-trends-for-2014 如今,已然到了Web横行的时代.越来越多的资 ...
- 投资学第一章 investments-introduction
转载请注明来自souldak,微博:@evagle 砖搬多了有点累,今天学学投资学. 这章主要是一些重要的概念. real assets / financial assets , fixed-in ...
- wxWidgets刚開始学习的人导引(2)——下载、安装wxWidgets
wxWidgets刚開始学习的人导引全目录 PDF版及附件下载 1 前言2 下载.安装wxWidgets3 wxWidgets应用程序初体验4 wxWidgets学习资料及利用方法指导5 用wxS ...
- JS学习笔记(一)基本数据类型和对象类型
js是一种弱类型的语言,所有的变量都用var进行声明,字符串用双引号或单引号括起来,常见基本数据类型为number,string,boolean等.如 var num = 123;或var num = ...