poj 1001Exponentiation

POJ 1001 - Exponentiation(求幂) 题目链接:POJ - 1001 题目概括: 求Rn R ∈ ( 0.0 , 99.999 ) 实数 n ∈ ( 0 , 25 ] 整数 题目解析: 看到样例输出,就发现不合适直接使用double类型来直接计算,应当使用数组来模拟乘法运算过程。 将实数R以字符串的形式读入,然后将小数点去除,转化成数组(倒序逐位储存),存储结果的数组,每个单元只存储1位数。数组空间开辟6*25=150稍大一点即可。 > 12.345 > a[0] = 5 a[1] = 4 a[2] = 3 a 阅读详情

好久没有敲代码了,这么水的一题我敲了2个小时= =!

主要考察高精度算法,注意判定条件,给定小数位,什么时候改把零省略,什么时候不可以。只有是在整数部分的前置零可以省略,结尾的零最后输出地时候处理一下。写得好丑啊~~~~

#include<iostream>

#include<cstring>
#include<cstdio>
using namespace std;
const int N = 200;
class  Bign{
public:
Bign(){
count = dot = 0;
}
void set(char *ss){
int l = strlen(ss);
count = dot = 0;
int j = 0;
for(int i = l-1;i>=0;i--){
if(ss[i]=='.'){
dot = j;
continue;
}
s[j++] = ss[i]-'0';
}
count = j;
}
void init(){
count = 1;
dot = 0;
s[0] = 1;
}
void reset(){
memset(s,0,sizeof(s));
}
int s[N];
int count;
int dot;
};
Bign mul(Bign a,Bign b){
int carry = 0;
int i,j;
Bign result;
result.reset();
for(i = 0;i<a.count;i++){
carry = 0;
for(j=0;j<b.count || carry;j++){
carry = carry+result.s[i+j];
if(j<b.count)carry+=a.s[i]*b.s[j];
result.s[i+j]=carry%10;
carry/=10;
}
}
int l = a.count+b.count+1;
result.dot = a.dot+b.dot;
while(l && result.s[l]==0 && l>result.dot){
l--;
}
if(l==0)result.count  = 1;
else result.count = l+1;

return result;
}
char R[8];
int n;
Bign pow(Bign a,int nn){
Bign tmp;
if(nn==0){
tmp.init();
return tmp;
}
if(nn==1)return a;
if(nn%2==1){
tmp = a;
Bign tmp = pow(a,nn/2);
tmp = mul(tmp,tmp);
return mul(tmp,a);
//return 
}else {
tmp = pow(a,nn/2);
return mul(tmp,tmp);
}
}
void p(Bign result){
///printf("%d\n%d\n",result.dot,result.count);
if(result.dot==0){
for(int i = result.count-1;i>=0;i--)printf("%d",result.s[i]);
printf("\n");
}
else if(result.dot>result.count){
printf(".");
for(int i = 0;i<result.dot-result.count;i++)printf("0");
int bottom = 0;
while(result.s[bottom]==0)bottom++;
for(int i = result.count-1;i>=bottom;i--)printf("%d",result.s[i]);
printf("\n");
}else{


int bottom = 0;
while(result.s[bottom]==0 && bottom<result.dot)bottom++;
bool istrue = false;
for(int i = result.count-1;i>=bottom;i--){
if(!istrue && result.s[i]==0);
else {
istrue = true;
printf("%d",result.s[i]);
}
if(i==result.dot && result.dot!=bottom){
printf(".");
istrue = 1;
}
}
printf("\n");


}
}
void solve()
{
Bign  r;
r.set(R);
r = pow(r,n);
p(r);
}
int main()
{

while(scanf("%s%d",&R,&n)!=EOF){
solve();
}
return 0;
}
智慧杯 考试必备 2019.4. 强密码 描述 我们称一个密码是强密码,当且仅当它满足以下所有条件: 由 8 − 16 个字符组成 至少包含一个大写字母 (A-Z) 至少包含一个小写字母 (a-z) 至少包含一个数字 (0-9) 至少包含一个特殊符号 (! @ #$ % & * _ +) 娇娇发现她现在的密码好像不是强密码,请你帮她计算一下最少添加几个 字符可以变成强密码? 输入 输入仅一行,一个字符串,表示娇娇当前的密码 输出 输出一个数表示答案 如果不需要添加任何字符就已. 阅读详情

相关推荐

Verilog仿真时读取bin文件模拟输入数据流,将输出数据流写入bin文件

需要关注的是,一般会省略文件起始地址和读取长度,那么mem为多大,就会从文件中读取多大的数据出来填充mem。如果只需要读取一次文件,那么代码到此就结束了,但是如果还需要每一帧都读取该文件转换为数据流,则在循环里判断新的一帧信号是否到来,在新的一帧再次打开一次文件,从头开始读取数据。

qq_41137205的博客 2774

POJ 1001 Exponentiation

POJ 1001 Exponentiation 心血来潮花了一上午做了这道恶心死人的高精度。展示一下打了各种补丁的程序。 type gj=record len:longint; data:array[1..1000]of longi...

aimifeng9177的博客 179

C语言编写Picard迭代和牛顿迭代法

为了完成学校计算方法的作业,花了两个多星期将所有实验报告编写出来,看到同桌找代码的辛苦,优快云也没有这类代码,我只是一时兴起,想分享我写的代码与大家共飨,有错误还请多多指正,代码都不难,也是为了让优快云帮我保存下,我辛辛苦苦做出来的,倘若能给别人带来一丝一毫的帮助,我都万分荣幸。 1:什么是Picard迭代 先弄一个满足f(x) = 0的函数将其转化为x= 正在上传… 重新上传 取消 ...

mohenxiang的博客 4700

POJ1001 Exponentiation (解题报告)

POJ1001 Exponentiation (解题报告)        原文: Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 90091   Accepted: 21443 Descrip

小龙的专栏 696

智能化运维(AIOps)

• 调查显示,54.79%的企业当前着重关注智能运维的质量领域(包括异常检测、告警收敛、根因分析、 故障处置等)能力建设,其次45.77%的企业关注效率领域,45.49%的企业关注成本领域,30.82%的 企业关注安全领域。从目前的发展情况来看,现阶段AIOps能力大多集中在L2级别, 主要以系统辅助分析,帮助人工进行决策和操作为主,较为领先的 能力实践可以达到L3级别,而L4和L5级别随着AIOps的技术发展 和能力的逐步增强,将是未来智能运维能力建设的发展方向和目标。

追求更专业的设计 3106

C语言实现AES加解密

C语言实现AES加解密 #include<stdio.h> #include<string.h> #include<time.h> #include<windows.h> #define Nb 4 //数据块行数 #define Nk 4 //密码块行数 #define Nr 10 //轮加密次数 unsigned char RoundKey[4*Nb*(Nr+1)]; //轮密钥 unsigned char Key[17];

qq_44310495的博客 8891

POJ1001 Exponentiation解题报告

POJ1001 Exponentiation解题报告 标签(空格分隔): C++ 参考:大数运算(4)——大数乘法 1.题目内容: Description Problems involving the computation of exact values of very large magnitude and precision are common. For exa...

但求效人无遗疏 410

Basilisk vs. STK:开源航天仿真工具在Windows上的实战体验与生态对比

本文对比了开源航天仿真工具Basilisk与商业软件STK在Windows平台上的实战体验与生态差异。从技术架构、安装配置、使用成本、功能覆盖、社区生态到适用场景,全面分析了二者的优劣势,为航天工程师和研究人员提供选型参考。Basilisk在性能和扩展性上表现突出,而STK在可视化与专业模块上更具优势。

weixin_30632089的博客 589

【北大poj】1001 Exponentiation

北大poj 1001 Exponentiation Description 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...

red_velvet_cake的博客 292

手把手教你解锁TI MSPM0G3507开发板(2025新版,附XDS110接线图)

本文详细解析了2025版TI MSPM0G3507开发板的解锁方法,针对新版硬件中BSL引脚的电路设计变化提供了精准接线方案和UniFlash软件配置步骤。通过实测数据和专业指导,帮助开发者解决芯片锁定问题,确保调试接口正常响应。

weixin_42696271的博客 810

人工蜂群优化算法(ABC)详解:原理、实现与应用

人工蜂群算法(Artificial Bee Colony, ABC)是Karaboga于2005年提出的一种群体智能优化算法,其灵感来源于蜜蜂群体在自然界中高效的采蜜行为。该算法通过模拟雇佣蜂、观察蜂和侦察蜂三种角色的分工协作来寻找最优解。在ABC算法中,每个潜在的解决方案被视为一个“食物源”,其质量由适应度函数评估。雇佣蜂负责在已知优质食物源附近进行局部开采;观察蜂根据雇佣蜂分享的信息,以一定概率选择并跟进优质食物源;侦察蜂则随机探索新区域,防止种群陷入局部最优。

qq_42212808的博客 393

POJ 1001 Exponentiation - 高精度高位数运算

/* * POJ 1001 Exponentiation * 求R^n, 其中0.0 < R < 99.999, 0 < n <= 25; * * 1) 高精度高位数计算; * 2) 将字符串转换为数组,按位计算; * 3) 采用连乘求幂 或 将次数转换为二进制数以减少相乘次数; * */#include using namespace std;#define MAX_NUMBER_LENGTH

ChenK在学习! 1005

2026年数学建模国赛论文排版规范:Word与LaTeX终极对比及模板

提前演练:不要等到比赛开始才第一次使用排版工具。至少在赛前一个月完成1-2篇模拟论文的全流程排版练习。建立检查清单:基于国赛规范制定排版检查清单,在提交前逐项核对——公式编号连续?图表引用准确?参考文献完整?页数不超限?善用模板但不止于模板:模板提供的是起点而非终点。根据自身需求调整宏包配置和样式参数,理解每一行配置的含义。关注评审体验:从评委的视角审视论文——重点内容是否突出?逻辑结构是否清晰?视觉层次是否合理?备份与容错:无论使用何种工具,建立多级备份机制。本地、云端、U盘各存一份,且定期保存历史版本。

YOLO 213

POJ-1001-Exponentiation

POJ-1001-Exponentiation http://poj.org/problem?id=1001 #include #include #include /* 95.123 12 0.4321 20 5.1234 15 6.7592 9 98.999 10 1.0100 12 548815620517731830194541.89902534341571597353

rock4you 393

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

POJ解题报告——1001 Exponentiation

POJ解题报告——1001 Exponentiation问题描述求高精度幂,输入是一个实数 R (0.0 < R < 99.999) 和 指数 n (0 < n <= 25), 要求精确计算 R 的 n 次方(Rn)。如 95.123 12 结果为548815620517731830194541.899025343415715973535967221869852721详见 http://poj.

drop_k的博客 509

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

高精度浮点数计算 poj 1001 Exponentiation

poj 1001 Exponentiation Time Limit Memory Limit Total Submissions Accepted 500ms 10000k 185164 44572 Descrimination   Problems involving the computation of exact values of very large magnitu...

weixin_40215124的博客 503

POJ 1001 Exponentiation(大数运算)

POJ 1001 Exponentiation 时限:500 ms 内存限制:10000 K 提交材料共计:179923 接受:43369 描述:求得数R( 0.0 < R < 99.999 )的n( 0 < n <= 25 )次方的精确值 样本输入 95.123 12 0.4321 20 5.12...

weixin_30455661的博客 160

poj1001_Exponentiation

poj1001_Exponentiation 这题真是超级大模拟。好繁琐,自己写的打数加法,乘法,写的比我大一时候写的要好很多,大一是借助C++里面的string来写的,这把只用了C,浇一次就ac了,挺开心的,不过写了2个小时啊。注意零的处理。大体思路就是先找出有多少位小数,要提前处理掉后面补充位置的零,然后把这个数转换成整数,做n次方,然后输...

weixin_30537451的博客 102

POJ1001 Exponentiation【高精度乘方】

题目: Description 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

淡然坊 1620

【模拟】poj 1001 Exponentiation (hdu 1063)

poj 1001 Exponentiation 大数大数 链接:http://poj.org/problem?id=1001 题意: 题意很简单,给你2个数(前面的是小数,后面是不超过25的整数),求得前一个数的幂(后一个数作指数部分)。 思路: 要求小数的幂,用一般的double,float完全满足不了解的需求。而且看到案例就知道肯定用大数解决。 大数解决最简单的看来是用JAVA

学无纸巾 502

【POJ】 1001 Exponentiation 大数

POJ 1001 ExponentiationDescription 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 ex

chutzpah 480

[POJ][1001]Exponentiation

Description 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 comp

软件工程学森 1万+

高精度浮点数幂次方 POJ 1001 Exponentiation

题目是在POJ上的第1001道 Exponentiation Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt

MysticalRzc的博客 1063

POJ1001 Exponentiation

Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 186075 Accepted: 44750 Description Problems involving the computation of exact values of very large magnitude and precision a...

浮生之居士 280

[POJ] 1001 Exponentiation

Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 188955 Accepted: 45370 Description Problems involving the computation of exact values of very large magnitude and p...

RoderickLi-努力努力再努力 269
下一篇: poj 1002 487-3279
贱走偏锋
博客等级 码龄15年 24粉丝 60原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值