洛谷P1932 A+B A-B A*B A/B A%B Problem
P1932 A+B A-B A*B A/B A%B Problem
题目背景
这个题目很新颖吧!!!
题目描述
求A、B的和差积商余!
由于数据有修改,减法运算结果可能带负号!
输入输出格式
输入格式:
两个数两行
A B
输出格式:
五个数
和 差 积 商 余
输入输出样例
说明
length(A),length(B)<=10^4
A,B>0
每个点3s。
/*
刚写完高精加减乘
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 20010
using namespace std;
int a[maxn],b[maxn],c[maxn];
struct node{
int len,zu[maxn];
bool operator < (const node x)const{
if(len!=x.len)return len<x.len;
for(int i=;i<=len;i++)
if(zu[i]!=x.zu[i])return zu[i]<x.zu[i];
}
node operator + (const node x)const{
node res;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(c,,sizeof(c));
int l=max(len,x.len);
for(int i=,j=len;i<=len;i++,j--)a[i]=zu[j];
for(int i=,j=x.len;i<=x.len;i++,j--)b[i]=x.zu[j];
for(int i=;i<=l;i++){
c[i]+=a[i]+b[i];
c[i+]=c[i]/;
c[i]%=;
}
while(c[l+]){
l++;
c[l+]=c[l]/;
c[l]%=;
}
for(int i=,j=l;i<=l;i++,j--)res.zu[i]=c[j];
res.len=l;
return res;
}
node operator - (const node x)const{
node res;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(c,,sizeof(c));
int l=max(len,x.len);
for(int i=,j=len;i<=len;i++,j--)a[i]=zu[j];
for(int i=,j=x.len;i<=x.len;i++,j--)b[i]=x.zu[j];
for(int i=;i<=l;i++){
if(a[i]<b[i])a[i]+=,a[i+]-=;
c[i]+=a[i]-b[i];
}
while(c[l]==)l--;
res.len=l;
for(int i=,j=l;i<=l;i++,j--){
res.zu[i]=c[j];
}
return res;
}
node operator * (const node x)const{
node res;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(c,,sizeof(c));
int l=len+x.len-;
for(int i=,j=len;i<=len;i++,j--)a[i]=zu[j];
for(int i=,j=x.len;i<=x.len;i++,j--)b[i]=x.zu[j];
for(int i=;i<=len;i++)
for(int j=;j<=x.len;j++)
c[i+j-]+=a[i]*b[j];
for(int i=;i<=l;i++){
c[i+]+=c[i]/;
c[i]%=;
}
while(c[l+]){
l++;
c[l+]=c[l]/;
c[l]%=;
}
while(c[l]==&&l>)l--;
if(l==)c[++l]=;
for(int i=,j=l;i<=l;i++,j--)res.zu[i]=c[j];
res.len=l;
return res;
}
}A,B;
char chA[maxn],chB[maxn];
int main(){
freopen("Cola.txt","r",stdin);
scanf("%s",chA+);
scanf("%s",chB+);
A.len=strlen(chA+);
B.len=strlen(chB+);
for(int i=;i<=A.len;i++)A.zu[i]=chA[i]-'';
for(int i=;i<=B.len;i++)B.zu[i]=chB[i]-'';
node he,cha,ji,shang,yu;
bool flag=;
if(A<B)swap(A,B),flag=;
he=A+B;
cha=A-B;
ji=A*B;
for(int i=;i<=he.len;i++)cout<<he.zu[i];cout<<endl;
if(flag)cout<<'-';
for(int i=;i<=cha.len;i++)cout<<cha.zu[i];cout<<endl;
for(int i=;i<=ji.len;i++)cout<<ji.zu[i];cout<<endl;
}
洛谷P1932 A+B A-B A*B A/B A%B Problem的更多相关文章
- 【洛谷p1932】A+B A-B A*B A/B A%B Problem
(emmmm) 这道题成功让我见识到了Dev撤回的高端大气上档(dàng)次. A+B A-B A*B A/B A%B Problem[传送门](真是个优秀的高精) 算法:::::::(模板题弄这么费 ...
- [洛谷OJ] P1114 “非常男女”计划
洛谷1114 “非常男女”计划 本题地址:http://www.luogu.org/problem/show?pid=1114 题目描述 近来,初一年的XXX小朋友致力于研究班上同学的配对问题(别想太 ...
- 洛谷1439 排列LCS问题
洛谷1439 排列LCS问题 本题地址:http://www.luogu.org/problem/show?pid=1439 题目描述 给出1-n的两个排列P1和P2,求它们的最长公共子序列. 输入输 ...
- 洛谷1640 bzoj1854游戏 匈牙利就是又短又快
bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...
- 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.
没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...
- 洛谷P1108 低价购买[DP | LIS方案数]
题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...
- 洛谷 P2701 [USACO5.3]巨大的牛棚Big Barn Label:二维数组前缀和 你够了 这次我用DP
题目背景 (USACO 5.3.4) 题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N ...
- 洛谷P1710 地铁涨价
P1710 地铁涨价 51通过 339提交 题目提供者洛谷OnlineJudge 标签O2优化云端评测2 难度提高+/省选- 提交 讨论 题解 最新讨论 求教:为什么只有40分 数组大小一定要开够 ...
- 洛谷P1371 NOI元丹
P1371 NOI元丹 71通过 394提交 题目提供者洛谷OnlineJudge 标签云端评测 难度普及/提高- 提交 讨论 题解 最新讨论 我觉得不需要讨论O long long 不够 没有取 ...
随机推荐
- [Luogu3960][NOIP2017]列队
luogu sol 震惊!\(NOIP\)居然也出数据结构! 话说回来,其实只需要对每一行的前\(m-1\)个人维护一个数据结构,然后对最后一列的\(m\)个人也维护一个数据结构就好了.具体的话写平衡 ...
- ACM学习历程—ZOJ3777 Problem Arrangement(递推 && 状压)
Description The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem sett ...
- P1607 [USACO09FEB]庙会班车Fair Shuttle
题目描述 Although Farmer John has no problems walking around the fair to collect prizes or see the shows ...
- Android App在Google App Store中搜不到
情景:Android App在Google App Store上架成功,三星手机可以在Google App Store中搜索到,但是三星tablet却无法在Google App Store中搜索到,目 ...
- C#中如何获取一个二维数组的两维长度,即行数和列数?以及多维数组各个维度的长度?
如何获取二维数组中的元素个数呢? int[,] array = new int[,] {{1,2,3},{4,5,6},{7,8,9}};//定义一个3行3列的二维数组int row = array. ...
- Parallel Programming-Paralle.For && ForEach
本文主要介绍Parallel.For以及Parallel.ForEach.Parallel.For是普通步长为1的for循环的并行代替方案.Parallel.ForEach是以集合为基准进行循环的fo ...
- bzoj 1941 [Sdoi2010]Hide and Seek——KDtree
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1941 第二道KDtree! 枚举每个点,求出距离它的最远和最近距离.O( n * logn ...
- bzoj 5120 无限之环 & 洛谷 P4003 —— 费用流(多路增广SPFA)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5120 https://www.luogu.org/problemnew/show/P4003 ...
- bean validator - Hibernate validator
在后台开发过程中,对参数的校验成为开发环境不可缺少的一个环节.比如参数不能为null,email那么必须符合email的格式,如果手动进行if判断或者写正则表达式判断无意开发效率太慢,在时间.成本.质 ...
- arm-linux-3.4.2移植for2440
----------------------------2440 上内核3.4.2移植------------------------ PS:因wifi项目中无wifi驱动,需新内核. 1.首先在内核 ...