【vijos P1010】清帝之惑之乾隆 c++题解
来源:互联网 发布:征途服务端linux版 编辑:程序博客网 时间:2024/04/28 13:39
题目描述
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 <= 9999.9) and n is an integer such that 0 < n <= 250.
This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R <= 9999.9) and n is an integer such that 0 < n <= 250.
输入格式
The input will consist of a set (less than 11) 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 to 10.
输出格式
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.
#include <stdio.h>#include <string>#include <iostream>#define MaxM 6100using namespace std;int c[MaxM];class Num{public :int len,point;int a[MaxM];void init(){len=0;point=0;for (int i=0;i<MaxM;i++) a[i]=0;}void rev(){for (int i=1;i<=len/2;i++){int tmp;tmp=a[i];a[i]=a[len-i+1];a[len-i+1]=tmp;}}void outfile(){int i=1,j=len;while (a[i]==0&&i<=len) i++;while (a[j]==0&&j>=1&&j>point) j--;for (j;j>=i;j--){if (j==point) cout<<'.';cout<<a[j];}cout<<endl;}Num &operator*(Num y){int i;for (int i=1;i<=len;i++) {c[i]=a[i];a[i]=0;}for (int i=1;i<=len;i++)for (int j=1;j<=y.len;j++){a[i+j-1]+=c[i]*y.a[j];a[i+j]+=a[i+j-1]/10;a[i+j-1]%=10;}len=len*y.len;point+=y.point;while (a[len]==0&&len>point+1) len--;return *this; }};Num P,Ans;void work(){string s;char ch;int N,count=0;while (ch!=EOF){cin>>s>>N;count++;if (N<0) return ;P.init(); Ans.init();P.len=1;P.a[1]=s[0]-'0';for (int i=1;i<=5;i++){if (s[i]=='.') P.point=5-P.len;else P.a[++P.len]=s[i]-'0';}P.rev();Ans.len=Ans.a[1]=1; Ans.point=0;for (int i=1;i<=N;i++) Ans=Ans*P;Ans.outfile();N=-1;}}int main(){freopen("p1010.in","r",stdin);freopen("p1010.out","w",stdout);work();return 0;}
0 0
- 【vijos P1010】清帝之惑之乾隆 c++题解
- 【高精度】Vijos P1010 清帝之惑之乾隆
- Vijos P1010 清帝之惑之乾隆
- vijos P1009 清帝之惑之康熙
- Vijos P1012 清帝之惑之雍正
- vijos P1009清帝之惑之康熙
- 【扩展欧几里德】Vijos P1009 清帝之惑之康熙
- 【动态规划】Vijos P1011 清帝之惑之顺治
- 【枚举】Vijos P1012 清帝之惑之雍正
- Vijos 1012 清帝之惑之雍正
- Vijos P1011 清帝之惑之顺治
- Vijos P1009 清帝之惑之康熙
- Vijos P1012 清帝之惑之雍正
- VIJOS-P1011 清帝之惑之顺治 dfs
- vijos之清帝之惑四题
- vijos 1011 清帝之惑之顺治 (记忆化搜索)
- VIJOS-P1011清帝之惑之顺治<滑雪> 【区间DP--相邻位】
- 乾隆的“十常四勿”之道
- gpgpu review
- 我第一个Python教程笔记
- 【多校第9场】【组合数学】【区间dp】【Expression】
- R语言基础绘图包--控制axis label位置--par(mgp)与mtext
- 【套汇】【bell-ford变形】
- 【vijos P1010】清帝之惑之乾隆 c++题解
- 将输入的字符串(字符串仅包含小写字母‘a’到‘z’),按照如下规则,循环转换后输出:a->b,b->c,…,y->z,z->a;若输入的字符串连续出现两个字母相同时,后一个字母需要连续转换2次。例如:
- 胜利大逃亡
- mac 上调试国产手机 手机连接不上
- class 文件格式
- 时间转换
- 第四周第二天
- 【ODPS】本地数据库数据批量上传到ODPS中
- Fragment 实现tab页卡切换并保存界面状态,动态添加Fragment