P1601 A+B Problem(高精)

题目描述

高精度加法,x相当于a+b problem,b不用考虑负数。

输入输出格式

输入格式:

分两行输入a,b<=10^500

输出格式:

输出只有一行,代表A+B的值

输入输出样例

输入样例:

1
1
输出样例:

2

比较简单的高精度。

高精度。顾名思义,就是在很大的位数情况下进行运算。(炸int)

其基本思想就是用数组进行模拟加法。

模拟近位。

最后遍历数组输出。

附代码:

 #include <cstdio>
#include <iostream>
using namespace std; struct diff{
int len;short x[]; void read(){
int len_read;
string read;
cin>>read;
len=;len_read=read.size();
for(int i=len_read-;i>=;i--)x[++len]=read[i]-;
} void write(){
for(int i=len;i>=;i--)printf("%d",x[i]);
printf("\n");
return ;
} struct diff operator+(struct diff tmp){
int c=;
struct diff ans;
ans.len=tmp.len;if(len>ans.len)ans.len=len;
for(int i=;i<=ans.len;i++)
{
ans.x[i]=x[i]+tmp.x[i]+c;
c=ans.x[i]/;ans.x[i]%=;
}
if(c>)ans.x[++ans.len]=c;
return ans;
}
}a,b; int main(){
a.read();b.read();a=a+b;a.write();
return ;
}

我们每个人都应该做到精益求精,所以还可以将普通高精度升华一下

那就是传说中的万进制高精度:

 #include <iostream>
#include <cstdio>
using namespace std;
string s1,s2;
int c,len,len1,a[],len2,b[]; void turn()
{
int x,y,lx=s1.size(),ly=s2.size(),l,r;
int c[],d[];
l=lx/;r=ly/;
x=lx-l*;y=ly-r*;
for(int i=;i<x;i++)c[]=c[]*+s1[i]-;
for(int i=;i<y;i++)d[]=d[]*+s2[i]-;
for(int i=;i<=l+;i++)c[i-(x==)]=(s1[*(i-)+x]-)*+(s1[*(i-)+x+]-)*+(s1[*(i-)+x+]-)*+(s1[*(i-)+x+]-);
for(int i=;i<=r+;i++)d[i-(y==)]=(s2[*(i-)+y]-)*+(s2[*(i-)+y+]-)*+(s2[*(i-)+y+]-)*+(s2[*(i-)+y+]-);
len1=l+(x>);len2=r+(y>);
for(int i=;i<=len1;i++)a[i]=c[len1-i+];
for(int i=;i<=len2;i++)b[i]=d[len2-i+]; } int main()
{
cin>>s1>>s2;
turn();
len=len1;if(len2>len)len=len2;
for(int i=;i<=len;i++)
{
a[i]=a[i]+b[i]+c;
c=a[i]/;
a[i]%=;
}
if(c>)a[++len]=c;
printf("%d",a[len]);
for(int i=len-;i>=;i--)printf("%04d",a[i]);
return ;/*万进制高精加*/
}

万进制高精加要注意输出“printf("%04d",a[i]);”

点个赞吧↓

 

题解 P1601 【A+B Problem(高精)】的更多相关文章

  1. [CEOI2007]树的匹配Treasury(树形DP+高精)

    题意 给一棵树,你可以匹配有边相连的两个点,问你这棵树的最大匹配时多少,并且计算出有多少种最大匹配. N≤1000,其中40%的数据答案不超过 108 题解 显然的树形DP+高精. 这题是作为考试题考 ...

  2. 洛谷 P1601 A+B Problem(高精)

    P1601 A+B Problem(高精) 题目背景 无 题目描述 高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b] 输入输出格式 输入格式 ...

  3. 【洛谷P1601 A+B Problem(高精)】

    题目背景 无 题目描述 高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b] 输入输出格式 输入格式: 分两行输入a,b<=10^500 ...

  4. 【洛谷p1601】A+B Problem(高精)

    高精度加法的思路还是很简单容易理解的 A+B Problem(高精)[传送门] 洛谷算法标签: 附上代码(最近懒得一批) #include<iostream> #include<cs ...

  5. 洛谷1601 A+B Problem(高精) 解题报告

    洛谷1601 A+B Problem(高精) 本题地址:http://www.luogu.org/problem/show?pid=1601 题目背景 无 题目描述 高精度加法,x相当于a+b pro ...

  6. 【题解】洛谷P2532 [AHOI2012]树屋阶梯(卡特兰数+高精)

    洛谷P2532:https://www.luogu.org/problemnew/show/P2532 思路 来自Sooke大佬的推导: https://www.luogu.org/blog/Sook ...

  7. 【题解】洛谷P1066 [NOIP2006TG] 2^k进制数(复杂高精+组合推导)

    洛谷P1066:https://www.luogu.org/problemnew/show/P1066 思路 挺难的一道题 也很复杂 满足题目要求的种数是两类组合数之和 r的最多位数m为 w/k(当w ...

  8. [bzoj2729][HNOI2012]排队 题解 (排列组合 高精)

    Description 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不 ...

  9. BZOJ_1002_[FJOI2007]_轮状病毒_(递推+高精)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1002 )*&*(^&*^&*^**()*) 1002: [FJOI20 ...

随机推荐

  1. Android开发——绘图基础

    前言: Android中绘图基本三个类,分别是Paint(画笔),Path(路径),Canvas(画布),这三个也是自定义View经常会使用到的类 个人理解,Canvas画布这个翻译其实不太好,这个类 ...

  2. Android破解学习之路(八)—— 进化之地内购破解

    最近在TapTap闲逛,看到了进化之地这款游戏,TapTap上有两个进化之地,一个是在TapTap直接购买的,另外一个则是试玩版,玩到中间就会有个购买完整版. 试玩版连接:https://www.ta ...

  3. java8 Stream操作

    Stream操作详解:https://www.ibm.com/developerworks/cn/java/j-lo-java8streamapi/#icomments

  4. Spring框架基础(下)

    log4J 导入log4J.jar 创建log4J.properties # Create a file called log4j.properties as shown below and plac ...

  5. mybatis基础(下)

    mybatis和spring整合 需要spring通过单例方式管理SqlSessionFactory spring和mybatis整合生成代理对象,使用SqlSessionFactory创建SqlSe ...

  6. CSS实现单行、多行文本超出部分显示省略号

     单行文本超出,代码如下: css代码: <style> .one{ width:200px; overflow: hidden; text-overflow:ellipsis; whit ...

  7. SVN系列操作(二)&svn不显示图标的解决方法

    接着上一篇文章,我们继续来操作一下SVN: 有同学反馈,我在本地上看到不SVN的图标,先解决一下这个问题. svn不显示图标的解决方法: 1.WIN+R,输入regedit,打开注册表 2.找到HKE ...

  8. DevOps 工程师实际上是做什么的

    DevOps 工程师实际上是做什么的? 我们之前已经讨论过许多关于DevOps和DevOps世界的最新趋势了.但是DevOps工程师到底是做什么的? DevOps工程师以最纯粹的方式弥合了软件开发和运 ...

  9. hadoop1.0 和 Hadoop 2.0 的区别

    1.Hadoop概述 在Google三篇大数据论文发表之后,Cloudera公司在这几篇论文的基础上,开发出了现在的Hadoop.但Hadoop开发出来也并非一帆风顺的,Hadoop1.0版本有诸多局 ...

  10. 安装最新nodejs

    # apt-get update # apt-get install -y python-software-properties software-properties-common # add-ap ...