POJ 1001

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 阅读详情

语言:java(没有用大数处理类,完全按照c++实现)

代码

package poj1001; //提交代码时不能包含

import java.util.Scanner;

/**
 * Created by fant on 17-3-21.
 */
public class Main {
    public static void main(String[] args) {
        Main tool = new Main();
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextBigDecimal()) {
            String flo = scan.nextBigDecimal().toString();
            int pow = scan.nextInt();
            //主体部分
            tool.handle(flo, pow);
        }
    }

    void handle(String flo, int pow) {
        int pointPos = flo.indexOf('.');
        int resultPointPos = (pointPos == -1 ? 0 : flo.length() - pointPos - 1) * pow;
        //去掉小数点
        if (pointPos != -1) {
            //需要进行 去小数点处理
            String front = flo.substring(0, pointPos);
            String end = flo.substring(pointPos + 1);
            flo = front + end;
        }
        // 计算出去掉小数点后的乘积
        String result = "1";
        for (int i = 0; i < pow; i++) {
            result = multiply(result, flo);
        }
        // 打印出正确结果
        System.out.println(convert_to_result(result, resultPointPos));
    }

    String convert_to_result(String num, int pos) {
        String result = "";
        if (pos == 0) {
            result = num;
        } else {
            String front = num.substring(0, num.length() - pos);
            String end = num.substring(num.length() - pos);
            result = front + "." + end;
        }

        int first_index_noZero = 0;
        while (result.charAt(first_index_noZero) == '0') {
            first_index_noZero++;
        }
        if (result.indexOf('.') != -1) {
            //是小数
            //去掉前导0
            result = result.substring(first_index_noZero);
            //去掉尾部0
            int last_index_noZero = result.length() - 1;
            while (result.charAt(last_index_noZero) == '0') {
                last_index_noZero--;
            }
            if (result.charAt(last_index_noZero) == '.') {
                // 1.0 1
                result = result.substring(0, last_index_noZero);
            } else {
                result = result.substring(0, last_index_noZero + 1);
            }

        } else {
            //不是小数
            result = result.substring(first_index_noZero);
        }

        return result;
    }

    static void myPrint(Object obj) {
        System.out.println(obj);
    }

    /**
     * 取出字符串str在index下标处的整数
     *
     * @param str
     * @param index
     * @return
     */
    int getIntFromIndex(String str, int index) {
        return str.charAt(index) - '0';
    }

    String format(String str, int totalCount) {
        int remainFrontZeroCount = totalCount - str.length();
        String temp = "";
        for (int i = 0; i < remainFrontZeroCount; i++) {
            temp = temp + "0";
        }
        return temp + str;
    }

    /**
     * 尾部添加0
     *
     * @param source
     * @param count  尾部0的个数
     * @return 处理后的字符串
     */
    String appendZero(String source, int count) {
        String temp = "";
        for (int i = 0; i < count; i++) {
            temp = temp + "0";
        }
        return source + temp;
    }

    /**
     * 乘积的辅助函数,用于求和
     *
     * @param arr
     * @return
     */
    String add(String[] arr) {
        String result = "";
        int itemLength = arr[0].length();
        int addition = 0;
        for (int i = itemLength - 1; i >= 0; i--) {
            int sum = 0;
            for (int j = 0; j < arr.length; j++) {
                sum = sum + getIntFromIndex(arr[j], i);
            }
            sum = sum + addition;
            // 进位
            addition = sum / 10;
            int newValue = sum - addition * 10;
            result = newValue + result;
        }
        result = addition + result;
        return result;
    }

    /**
     * 处理整数乘法
     *
     * @param op1 第一个操作数
     * @param op2 第二个操作数
     * @return 乘积
     */
    String multiply(String op1, String op2) {
        String result = "";
        int sumItemCount = op2.length();
        String[] sumItemArr = new String[sumItemCount];
        for (int i = op2.length() - 1; i >= 0; i--) {
            int additionalItem = 0;
            sumItemArr[i] = "";
            int b = getIntFromIndex(op2, i);
            for (int j = op1.length() - 1; j >= 0; j--) {
                int a = getIntFromIndex(op1, j);
                // 乘积
                int ji = a * b + additionalItem;
                // 进位
                additionalItem = ji / 10;
                int newValue = ji - additionalItem * 10;
                sumItemArr[i] = String.valueOf(newValue) + sumItemArr[i];
            }
            sumItemArr[i] = String.valueOf(additionalItem) + sumItemArr[i];
            // 添加尾部0
            int tailZeroCount = op2.length() - 1 - i;
            sumItemArr[i] = appendZero(sumItemArr[i], tailZeroCount);
//            System.out.println(sumItemArr[i]);
        }//所有累加项均已求出
        // 添加首部0
        int length = sumItemArr[0].length();
        for (int i = 0; i < sumItemCount; i++) {
            sumItemArr[i] = format(sumItemArr[i], length);
        }
        // 求和
        result = add(sumItemArr);
        return result;
    }
}
POJ1001-C++ POJ1001 文章目录POJ1001题目描述:代码: 题目描述: ​ 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 computer systems. This p 阅读详情

相关推荐

POJ1001解题报告

乍一看就是大数乘法问题,要通过可不是那么容易

上善若水 1859

POJ 1001——高精度快速幂

POJ 1001——高精度快速幂 本题主要用到两个东西,一个是高精度,一个是快速幂。 虽然是浮点数的乘法,但是实际上可以转化为整数的乘法,然后再用高精度乘法,高精度算法本身不难,但是在没重载运算符的情况下使用数组还是挺麻烦的,不少地方的初始化都需要特别注意。 关于数组的初始化: 数组名在函数内部时,它的sizeof数组名获得的是数组本身的长度,而数组作为函数形参的时候,sizeof获得的是这个指针本身的长度,这一点特别坑,这会导致memset函数出现问题。 关于快速幂: 快速幂是一种快速求出数字的幂的方法,

qq_43513855的博客 1228

poj1001解题报告

<br /> ExponentiationTime Limit: 500MS Memory Limit: 10000KTotal Submissions: 80517 Accepted: 19098<br />DescriptionProblems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the nat

neoxuhaotian的专栏 9230

poj1001(大数据)

这个问题是要请你求出 Rn 的精确值。在这里R是一个实数(0.0 Input 每组测试资料一列,包含了R,n,R的位置为第1行到第6行,n的位置为第8行到第9行。 Output 输出 Rn 的精确值。前后方无作用的0不应该出现。 Sample input 95.123 12 0.4321 20 5.1234 15 6.7592 9

u014236804的专栏 721

poj1001源码

poj1001源码,c语言版,通过ac,包含注释,容易懂

POJ 1001 Exponentiation 求高精度幂 C源代码

如题所示,亲测可用。求高精度幂,不会的同学可以参考下,会做的同学可以给挑挑毛病!大家以代码会友!

POJ 1001(浮点数高精度幂) 解题报告

/*__________________________________________________POJ 1001题______________________________________________________ 求高精度幂 Time Limit: 500MS Memory Limit: 10000K Tot

Why So Serious? 2879

poj1001高精度乘法

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 < 99.999 ) and n is an integer such that 0 < n <= 25. 输入说明 The input will consist of a set 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 and 9. 输出说明 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. 输入样例 95.123 12 0.4321 20 5.1234 15 6.7592 9 98.999 10 1.0100 12 输出样例 548815620517731830194541.899025343415715973535967221869852721 .00000005148554641076956121994511276767154838481760200726351203835429763013462401 43992025569.928573701266488041146654993318703707511666295476720493953024 29448126.764121021618164430206909037173276672 90429072743629540498.107596019456651774561044010001 1.126825030131969720661201 小提示 If you don't know how to determine wheather encounted the end of input: s is a string and n is an integer C++ while(cin>>s>>n) { ... } c while(scanf("%s%d",s,&n)==2) //to see if the scanf read in as many items as you want /*while(scanf(%s%d",s,&n)!=EOF) //this also work */ { ... } 来源 East Central North America 1988 北大OJ平台(代理

POJ 1001解题思路

POJ 1001是高精度大数相乘的题目

SSWDG123456的专栏 1172

POJ1001的一个解决方案

简单地poj1001代码,是典型的利用数组输出结果的方法,关键的是测试数据。

LSCM最小二乘保角参数化

LSCM最小二乘保角参数化 最小二乘思想 已知一组点的数据(x,y) x x1x_1x1​ x2x_2x2​ x3x_3x3​ … xnx_nxn​ y y1y_1y1​ y2y_2y2​ y3y_3y3​ … yny_nyn​ 可以近似为线性关系 y=ax+by=ax+by=ax+b ,目标为确定常数 aaa , bbb ; 解法:找到 aaa , bbb ,使得所有 yiy_iyi​ 与 axi+bax_i+baxi​+b 偏差的平方和 Q=∑i=1n(yi−axi−b)2 Q=\s

weixin_49732532的博客 4252

POJ 1001源码笔记

1. POJ 1001 题目要求: 对一个实数R( 0.0 < R < 99.999 ),要求写程序精确计算 R 的 n 次方(Rn),其中n 是整数并且 0 < n <= 25。 Input T输入包括多组 R 和 n。 R 的值占第 1 到第 6 列,n 的值占第 8 和第 9 列。 Output 对于每组输入,要求输出一行,该行包含精确的 R 的 n 次方。输出需要去...

qq_34892250的博客 290

深入博通PEX89000内部:那颗ARM CPU和Synthetic Mode到底能玩出什么花样?

本文深入解析博通PEX89000系列PCIe交换芯片内置的ARM CPU与Synthetic Mode技术,揭示其在AI计算和数据中心的智能潜能。通过ARM Cortex CPU的实时控制和Synthetic Mode的自治网络功能,PEX89000实现了GPU集群的动态拓扑重组和资源池化,大幅提升AI训练效率。文章还探讨了该技术在软件定义数据平面和弹性AI架构中的创新应用。

weixin_30776273的博客 209

POJ 1001(大数相乘)

POJ1001 题意:输入m,n 求m的n次方。 /*需要注意的点太多了,没事就多打几遍*/ #include #include #include using namespace std; int point; void ridzero(char a[]) { int i; i = strlen(a) - 1; while(a[i] == '0'){

Since_natural_ran 440

基于 LSTM 的船舶轨迹预测,单步预测

基于 LSTM 的船舶轨迹预测,单步预测

fyuhao的博客 1万+

在 TASKPROCESSING 上为 ABAP OData 服务添加多个系统别名:从原理到落地的完整实践

本文面向SAP Gateway与ABAP开发者,详细讲解如何在TASKPROCESSING OData服务上添加系统别名。首先介绍了系统别名的概念与设计初衷,阐述了添加别名的业务场景需求,包括多系统接入、用户分流和灰度发布等。随后提供了标准配置步骤,从SPRO路径到具体操作说明,并分享了三个实际案例说明如何实现跨区域统一待办、按用户角色分流和灰度发布。最后给出了验证方法和常见问题解决方案,帮助开发者掌握这项基础但关键的配置技能,实现服务路由的可控管理。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 136

【北大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

第七节:Vben Admin 最新 v5.0 (vben5) + Python Flask 快速入门 - 用户管理(上)

本节的内容是用户管理,后端Python代码的实现。

cuiwin的专栏 775

POJ 1001 Exponentiation

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

aimifeng9177的博客 179

Qwen2-VL出现RuntimeError: CUDA error: too many resources requested for launch CUDA kernel errors的解决方案

本文主要介绍了Qwen2-VL出现RuntimeError: CUDA error: too many resources requested for launch CUDA kernel errors的解决方案,希望能对使用Qwen2-VL的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 13万+

GraphRAG深度解析:架构设计与实战案例

生成模块结合检索到的图数据和用户输入的查询,生成高质量的文本输出。通过结合图数据库中的知识,模型可以更准确地回答用户的问题,提供更优质的客户服务。通过分析用户的行为和偏好,结合图数据库中的知识,模型可以为用户提供个性化的推荐。:通过图数据库存储和检索结构化的知识,为语言模型提供丰富的背景信息,提升生成内容的质量和准确性。:选择合适的图数据库,如Neo4j、OrientDB等,以支持高效的图数据存储和检索。:利用图数据库的高效检索能力,快速找到与用户查询最相关的图元素,提高系统的响应速度。

加入“Super Entity”,与全能开发团队共探AI智能体与数字人项目,开启前沿技术之旅。 1589

poj1001

3.13 2019 poj 泛做 主要选择AC ratio 20% - 30%的题目在做 poj1001 高精度幂 先将小数当成整数,记录数点位置 进行高精度乘法,还原小数点位置 处理前导0,后导0,其实并不难 blog1,blog2 #include <iostream> #include <cstdio> #include <cstdlib> #incl...

weixin_33918114的博客 121

第51节:cesium 范围查询(含源码+视频)

cesium 范围查询

qq_29384639的博客 1495

POJ-1001

来源:http://poj.org/problem?id=1001&lang=zh-CN 这题没什么算法可言,主要是各种情况的处理。 思路:先忽略小数点,算完后输出时在适当的位置输出一个小数点就行了,完全按照高精度乘单精度的方法。至于小数点的输出,因为每乘一次带小数点的数,小数位数相加就是了。 给出几种特殊情况: 25 2 25.0 2 0....

anyuan5299的博客 117

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

上一篇: qt5.8编译mysql
下一篇: django中settings.py设置
FantDing
博客等级 码龄10年 3粉丝 34原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值