杭电ACM大数JAVA提交实例

杭电ACM 1002大数相加 两种方法 A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 316067    Accepted Submission(s): 61349 Problem Description I have 阅读详情

(提交时需将类名改为Main)

1002A + B Problem II

Problem Description

I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

Input

The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000. 

Output

For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.

Sample Input

2

1 2

112233445566778899 998877665544332211

Sample Output

Case 1:

1 + 2 = 3

 

Case 2:

112233445566778899 + 998877665544332211 = 1111111111111111110

import java.math.BigInteger; 
import java.util.Scanner; 
  
public class Main{ 
    public static void main(String args[]){ 
        BigInteger a = BigInteger.valueOf(0),b = BigInteger.valueOf(0); 
        int c; 
        Scanner cin = new Scanner(System.in); 
        boolean flag = false; 
        while(cin.hasNextInt()){ 
            c = cin.nextInt(); 
            for(int i = 1;i<=c;i++){ 
                a = cin.nextBigInteger(); 
                b = cin.nextBigInteger(); 
                if(flag){ 
                    System.out.println(); 
                } 
                flag = true; 
                System.out.println("Case "+i+":"); 
                System.out.println(a+" + "+b+" = "+a.add(b)); 
            } 
        } 
    } 
} 

 

1042N!

Problem Description

Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!

Input

One N in one line, process to the end of file.

Output

For each N, output N! in one line.

Sample Input

1

2

3

Sample Output

1

2

6

import java.math.BigInteger;

import java.util.Scanner;

 

public class Main{

    public static void main(String[] args) {

        int n;

        BigInteger mul;

        Scanner cin = new Scanner(System.in);

        while (cin.hasNextInt()) {

            n = cin.nextInt();

            mul = BigInteger.ONE;

            for (int i = 1; i <= n; i++) {

                mul = mul.multiply(BigInteger.valueOf((long) i));

            }

            System.out.println(mul);

        }

    }

}

 

1047Integer Inquiry

Problem Description

One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers.
``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.)

Input

The input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).
The final input line will contain a single zero on a line by itself.

Output

Your program should output the sum of the VeryLongIntegers given in the input.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.

Sample Input

1

123456789012345678901234567890

123456789012345678901234567890

123456789012345678901234567890

0

Sample Output

370370367037037036703703703670

import java.math.BigInteger; 
import java.util.Scanner; 
  
public class Main{ 
    public static void main(String[] args) { 
        int n; 
        BigInteger tmp, res; 
        boolean flag = false; 
        Scanner cin = new Scanner(System.in); 
        cin.hasNextInt(); 
        n = cin.nextInt(); 
        for (int i = 0; i < n; i++) { 
            if (flag) 
                System.out.println(); 
            flag = true; 
            res = BigInteger.ZERO; 
            while (cin.hasNextBigInteger()) { 
                tmp = cin.nextBigInteger(); 
                if (tmp.intValue() == 0) 
                    break; 
                res = res.add(tmp); 
            } 
            System.out.println(res); 
        } 
    } 
} 

1063Exponentiation

Problem 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 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.

Input

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.

Output

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.

Sample Input

95.123 12

0.4321 20

5.1234 15

6.7592  9

98.999 10

1.0100 12

Sample Output

548815620517731830194541.899025343415715973535967221869852721

.00000005148554641076956121994511276767154838481760200726351203835429763013462401

43992025569.928573701266488041146654993318703707511666295476720493953024

29448126.764121021618164430206909037173276672

90429072743629540498.107596019456651774561044010001

1.126825030131969720661201

 

import java.math.BigDecimal;

import java.util.Scanner;

public class Main{

    public static void main(String args[]) {

        BigDecimal r, mul;

        int n;

        Scanner cin = new Scanner(System.in);

        while (cin.hasNextBigDecimal()) {

            r = cin.nextBigDecimal();

            mul = BigDecimal.ONE;

            n = cin.nextInt();

            for (int i = 0; i < n; i++) {

                mul = mul.multiply(r);

            }

            String str = mul.stripTrailingZeros().toPlainString();

            if (str.charAt(0) == '0')

                System.out.println(str.substring(1));

            else

                System.out.println(str);

        }

    }

}

 

1316How Many Fibs?

Problem Description

Recall the definition of the Fibonacci numbers:
f1 := 1
f2 := 2
fn := fn-1 + fn-2 (n >= 3)
Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a, b].

Input

The input contains several test cases. Each test case consists of two non-negative integer numbers a and b. Input is terminated by a = b = 0. Otherwise, a <= b <= 10^100. The numbers a and b are given with no superfluous leading zeros.

Output

For each test case output on a single line the number of Fibonacci numbers fi with a <= fi <= b.

Sample Input

10 100

1234567890 9876543210

0 0

Sample Output

5

4

import java.math.BigInteger; 
import java.util.Scanner; 
  
public class Main{ 
    public static void main(String args[]) { 
        BigInteger count; 
        BigInteger f[] = new BigInteger[10005]; 
        BigInteger a = BigInteger.valueOf(0), b = BigInteger.valueOf(0); 
        f[1] = BigInteger.valueOf(1); 
        f[2] = BigInteger.valueOf(2); 
        for (int i = 3; i < 10005; i++) { 
            f[i] = f[i - 1].add(f[i - 2]); 
        } 
        Scanner cin = new Scanner(System.in); 
        while (cin.hasNextBigInteger()) { 
            a = cin.nextBigInteger(); 
            b = cin.nextBigInteger(); 
            if (a.equals(BigInteger.valueOf(0)) 
                    && b.equals(BigInteger.valueOf(0))) { 
                break; 
            } else { 
                count = BigInteger.valueOf(0); 
                for (int i = 1; i < 10000; i++) { 
                    if (((a.compareTo(f[i]) == -1) || (a.compareTo(f[i]) == 0)) 
                            && ((b.compareTo(f[i]) == 1) || (b.compareTo(f[i]) == 0))) { 
                        count = count.add(BigInteger.valueOf(1)); 
                    } 
                } 
                System.out.println(count); 
            } 
        } 
    } 
} 

1715大菲波数

Problem Description

Fibonacci数列,定义如下:
f(1)=f(2)=1
f(n)=f(n-1)+f(n-2) n>=3。
计算第n项Fibonacci数值。

Input

输入第一行为一个整数N,接下来N行为整数Pi(1<=Pi<=1000)。

Output

输出为N行,每行为对应的f(Pi)。

Sample Input

5

1

2

3

4

5

Sample Output

1

1

2

3

5

import java.io.*; 
import java.util.*; 
import java.math.*; 
public class Main{ 
    public static void main(String[] args) { 
        int n; 
        BigInteger f[] = new BigInteger[1005]; 
        f[1] = BigInteger.valueOf(1); 
        f[2] = BigInteger.valueOf(1); 
        for (int i = 3; i < 1005; i++) { 
            f[i] = f[i - 1].add(f[i - 2]); 
        } 
        Scanner cin = new Scanner(System.in); 
        while (cin.hasNextInt()) { 
            n = cin.nextInt(); 
            int p; 
            for (int i = 0; i < n; i++) { 
                p = cin.nextInt(); 
                System.out.println(f[p]); 
            } 
        } 
    } 
} 

1753大明A+B

Problem Description

话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫“大明”。
这时他已经不是那个只会做100以内加法的那个“小明”了,现在他甚至会任意长度的正小数的加法。
现在,给你两个正的小数A和B,你的任务是代表大明计算出A+B的值。

Input

本题目包含多组测试数据,请处理到文件结束。
每一组测试数据在一行里面包含两个长度不大于400的正小数A和B。

Output

请在一行里面输出输出A+B的值,请输出最简形式。详细要求请见Sample Output。

Sample Input

1.1 2.9

1.1111111111 2.3444323343

1 1.1

Sample Output

4

3.4555434454

2.1

import java.io.*; 
import java.util.*; 
import java.math.*; 
  
public class Main { 
    public static void main(String[] args) { 
        BigDecimal a, b; 
        Scanner cin = new Scanner(System.in); 
        while (cin.hasNextBigDecimal()) { 
            a = cin.nextBigDecimal(); 
            b = cin.nextBigDecimal(); 
            a = a.add(b); 
            String str = a.stripTrailingZeros().toPlainString(); 
            System.out.println(str); 
        } 
    } 
} 

 

杭电ACM OJ 1002 A + B Problem II 大数问题 长整数问题 A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 381958    Accepted Submission(s): 74267 Problem Description I have 阅读详情

相关推荐

java实现杭电acm1到23题

杭电acm的前23题,有几道没做,我是新手,很多方法比较暴力,只是看到这些题java实现的实在不好找,就贴出来供新手一块交流,希望对你们有用。 有些是自己敲的,有些是参考别人写的,如果后面有再做我也会贴出来的。

【大数】N!

描述 Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! 输入 One N in one line, process to the end of file. 输出 For each N, output N! in one line. 样例输入 1 2 3 样例输出 1 2 6 代码: #include<bits/st...

Skynamer的博客 252

Molflow新手必看:Facet基础操作全解析(从2D建模到3D拉伸)

本文为Molflow新手提供了Facet基础操作的全面解析,涵盖从2D图形创建到3D模型拉伸的完整流程。详细介绍了Facet作为几何建模基石的核心概念、顶点编辑、布尔运算以及拉伸、放样等关键操作,并深入讲解了如何为其配置物理参数以实现真空系统的蒙特卡洛模拟。

prometheus9mon的博客 417

HDU 1042 求N! ---大数乘法

Problem Description: Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input: One N in one line, process to the end of file. Output: For each N, output N! in one line.

Epic丶玖遇 1322

中心对数比变换(Centered Log Ratio Transformation,CLR)的原理及scikit-bio介绍

中心对数比变换(Centered Log Ratio Transformation,CLR)是一种数据预处理方法,常用于成分数据分析领域。在成分数据中,各成分之间通常存在一定的约束关系,比如它们的和为固定值等,中心对数比变换可以有效地处理这种具有特殊约束的数据。官方文档scikit-bio是一个在Python3中处理生物数据的库成分统计 (skbio.stats.composition )模块中的,此函数将组合从Aitchison几何体转换到真实空间。这个clr。

RECORD LEARN PROGRESS 1万+

手把手教你为ArduPilot添加自定义飞行模式:以自动巡检航线为例

本文详细介绍了如何为开源飞控ArduPilot添加自定义飞行模式,并以自动巡检航线为例,提供了从状态机设计、代码实现到地面站集成的完整开发指南。通过七步法手把手教学,帮助开发者深入理解飞控核心逻辑,实现无人机自主执行复杂巡检任务,满足行业应用定制需求。

weixin_29306875的博客 137

杭电1042—— N!(大数乘法的应用!)

N! Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one line, process to the end of file. Output For each N, output N! i...

编程语言小筑 297

避坑指南:SAP成本中心分割结构配置常见错误及解决(含KA06/KL01前置步骤)

本文深入解析了SAP成本中心会计中分割结构配置的关键步骤与常见错误。重点强调了配置前必须通过KA06创建次级成本要素(类别42)和通过KL01创建活动类型这两个核心前置步骤,并详细剖析了在OKES中定义分割规则及版本时的高频报错原因与解决方案,帮助顾问和运维人员有效规避配置陷阱,确保成本分摊的准确性。

pear55的博客 865

HDOJ1042

题目: Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!   Input One N in one line, process to the end of file.   Output For each N, output N! in one l

StormMaybin的博客 562

泛微OA与金蝶云星空深度集成实战:审批与表单双场景解析

本文深入解析泛微OA与金蝶云星空的深度集成实战,聚焦审批流程与表单对接两大核心场景。通过具体案例,详细阐述了如何实现业务数据与审批流程的自动联动,打破数据孤岛,提升企业运营效率与数据一致性,并分享了接口设计、安全策略及实战避坑指南。

4k5l6j7h8的博客 466

dToF直方图之美_deadtime死区时间

IMX459的死区时间可以在6ns,这个时间是什么级别,车载激光雷达激光器的光脉宽一般都在4ns以上,也就是这个时间贴近去SPAD的死区时间,这就导致了pile up会非常弱,不会有太多数量的光子计数堆积,加上某些SPAD设计,对TDC有一些更深入的考量,所以不需要去校正pile up算法。Sensor层面决定了pile up的复杂程度,如果一个dToF的SPAD一致性非常好,那么pile up校正可以简单到极致,也就是一句代码的事,比如IMX611,优秀到不需要后端去考虑校正pile up。

dream it possible 1435

N!

链接:https://cn.vjudge.net/problem/HDU-1042 题目:N! Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one line, process to the end of file. Output For each N, output ...

weixin_43890535的博客 295

【Qt】解决 FTH: (11284): *** Fault tolerant heap shim applied to current process. (亲测有效)

计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers。容错堆垫片应用到当前的过程。这通常是由于以前的崩溃。win + r,输入regedit。

Fanjufei的博客 830

杭电acm java怎么提交_杭电ACM大数JAVA提交实例

1002A + B Problem IIProblem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of the input contains an integer ...

weixin_42651887的博客 289

1.DJI-payload SDK负载开发准备和硬件连接及运行示例代码

大疆psdk开发环境

哒宰的博客 1442

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

杭电java期末试卷2015_杭电上用JAVA提交的几道简单题

杭电ACM大数JAVA提交实例(提交时需将类名改为Main)1002A + B Problem IIProblem DescriptionI have a very simple problem for you. Given two integers Aand B, your job is to calculate the Sum of A + B.InputThe first line of t...

weixin_28812943的博客 992

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

杭电1005java_杭电ACM 1005 java

杭电ACM 1005 java关注:91答案:1mip版解决时间 2021-02-01 05:41提问者一曲柔音、驱散离愁2021-01-31 17:18A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and ...

weixin_42498909的博客 266

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

杭电acm刷题顺序Java_杭电ACM刷题顺序

第一阶段:开始入门吧!(15天,53题)输入输出练习(2天,10题)1000、1089—1096、1001简单操作:(2—4天,12题)2000—2011、2039英文题试水(3—4天,8题)1720、1062、2104、1064、2734、1170、1197、2629回归水题(4-6天,24题)2012—2030、2032、2040、2042、2054、2055第二阶段:我要学算法!(12天,3...

weixin_35304361的博客 781

杭电ACM Q1002

杭电ACM Q1002 版权声明:本文为博主原创文章,未经博主允许不得转载。 Problem Description I have a very simple problem for you. Given two integers A and B, your job is to cal...

chongguiyu7286的博客 114

杭电ACM OJ 1023 Train Problem II 卡特兰数 + 大数乘法 轻松解决出栈情况计数

Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10121    Accepted Submission(s): 5407 Problem Description As we al

qq_36523667的博客 590

杭电oj1002Java实现

杭电oj 1002 题目描述: 代码实现: 可以直接使用Java中的大整形。注意输出格式要求,换行、空格等。 实现1: import java.lang.reflect.Array; import java.util.*; import java.util.LinkedList; import java.math.BigInteger; public class Main { ...

qq_41971768的博客 7867

杭电ACM——Java版

记录杭电ACM的部分答案,纯手写,如有雷同,算你抄我的。o(∩_∩)o

young_kim的技术博客 3489

杭电ACM_1753

杭电OJ1753 大数处理,java的优势一下就凸显出来了 用到的函数 add(); toPlainSting(); 转换成朴素的字符类型 compareTo(); 比较函数 stripTrailingZeros(); 去后导0这题把输入的数据转换成小数类型,去前导0,然后相加,输出时去后导0,再转换成字符类型输出。import java.ut

Hellotanbin的博客 907

杭电 —1212 大数取模

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7152    Accepted Submission(s): 4934 Problem Description As we know, Big

lu_1110的博客 571
上一篇: 初识Android之简单实例
下一篇: 初识Android之xml解析
ITSource
博客等级 码龄15年 12粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值