HD-ACM算法专攻系列(10)——大明A+B

题目描述:

源码:

需要注意的一点是输出是最简形式,需要去除小数的后导0,而调用stripTrailingZeros()函数后,数会以科学计数法输出,所以需要调用toPlainString().

import java.math.BigDecimal;
import java.util.*;

public class Main
{
		//主函数
        public static void main(String[] args)
        {
            BigDecimal a, b;
			Scanner cin = new Scanner(System.in);

			while(cin.hasNext())
			{
				a = cin.nextBigDecimal();
				b = cin.nextBigDecimal();
				System.out.println((a.add(b)).stripTrailingZeros().toPlainString());
			}
		}
}

  

时间: 2024-08-26 03:40:24

HD-ACM算法专攻系列(10)——大明A+B的相关文章

HD-ACM算法专攻系列(23)——Crixalis's Equipment

题目描述: AC源码:此次考察贪心算法,解题思路:贪心的原则是使留下的空间最大,优先选择Bi与Ai差值最大的,至于为什么?这里用只有2个设备为例,(A1,B1)与(A2,B2),假设先搬运A1,搬运的那一瞬间,实际将要占用的空间应该为A1+B2,那么为了保证留下的空间最大,则应该有A1+B2<A2+B1成立,才能先搬运A1,即B1-A1>B2-B1.(n个设备可以两两做这样的比较,来达到选择的最优) #include"iostream" #include"algo

HD-ACM算法专攻系列(17)——考试排名

问题描述: 源码: 主要要注意输出格式. #include"iostream" #include"iomanip" #include"algorithm" #include"string" using namespace std; struct Person { string name; int count; int score; }; bool cmp(Person a, Person b) { if(a.count >

HD-ACM算法专攻系列(7)——排序

题目描述: 源码: #include"iostream" #include"string" using namespace std; void Order(int *p, int n) { int tmp; if(n < 2)return; for(int i = 0; i < n - 1; i++) { for(int j = 0; j < n - i - 1; j++) { if(p[j] > p[j + 1]) { tmp = p[j]

HD-ACM算法专攻系列(16)——find your present (2)

题目描述: 源码: #include"iostream" #include"string" using namespace std; bool IsFirstHalf(string *strs, int n, string str) { int count = 0; for(int i = 0; i < n; i++) { if(str < strs[i])count++; } return count >= (n / 2 + n % 2); }

HD-ACM算法专攻系列(21)——Max Sum

问题描述: AC源码: 此题考察动态规划,解题思路:遍历(但有技巧),在于当前i各之和为负数时,直接选择以第i+1个为开头,在于当前i各之和为正数时,第i个可以不用作为开头(因为前i+1个之和一定大于第i+1个的值) #include"iostream" using namespace std; int main() { int t, n, start, end, sum, max, tmp; int a[100000]; scanf("%d", &t);

HD-ACM算法专攻系列(19)——七夕节

问题描述: AC源码: /**/ #include"iostream" #include"cmath" using namespace std; int main() { int t, n, sq, sum; scanf("%d", &t); for(int i = 0; i < t; i++) { scanf("%d", &n); sum = 1; sq = (int)sqrt(n); for(int

HD-ACM算法专攻系列(14)——Quoit Design

问题描述: 源码: 经典问题--最近邻问题,标准解法 #include"iostream" #include"algorithm" #include"cmath" using namespace std; struct Point { double x; double y; }; Point S[100000];//不使用全局变量可能会超内存 bool cmpPointX(Point a, Point b) { return a.x > b

HD-ACM算法专攻系列(4)——A == B ?

题目描述: 源码: /**/ #include"iostream" #include"string" using namespace std; string Standard(string str) { int start; int len = str.length(); char * p = new char[len + 2]; start = 0; if(str[0] == '-' || str[0] == '+') { p[0] = str[0]; start

如何出一道ACM算法题?

本文背景 本人算法能力一般,但是为省赛和区域赛网络赛出过几道题,总结了一些自己的经验,希望与大家分享.本文不涉及具体的算法题,都是一些理论性的想法和一些建议. 题源 如果你能在没有题源的情况下自己想出一道新的题目,想必也很难看到这篇文章了.题源是出题的第一步,相信到了需要出题的地步,正在看这篇博客的你一定有自己熟悉的刷题网站,而这个网站可以作为你的题源,因为熟悉.本人推荐两个题源网站: 英文题源网站 Codeforce 中文题源网站 51nod 拿到的题源一定要确保只能能够写出所有解法,可能题目