洛谷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 不够 没有取 ...
随机推荐
- python3反射解析
python反射解析 一. 简介 python中的反射功能是由以下四个内置函数提供:hasattr.getattr.setattr.delattr,改四个函数分别用于对对象内部执行:检查是否含有某 ...
- pow,sqrt使用时需注意
使用时注意类型,可见两者皆不可以用int 1.pow 函数声明: double pow (double base , double exponent); float pow (float base , ...
- POJ1363 Rails 验证出栈序列问题
题目地址: http://poj.org/problem?id=1363 此题只需验证是否为合法的出栈序列. 有两个思路: 1.每个已出栈之后的数且小于此数的数都必须按降序排列.复杂度O(n^2),适 ...
- Hibernate学习---第十节:Hibernate之QBC、样例查询&离线查询
一.QBC (Query By Criteria) 主要有Criteria,Criterion,Oder,Restrictions类组成 1.java 代码如下: /** * 查询所有 */ @Tes ...
- Selenium-元素定位与操作
UI的自动化本质就是识别元素,操作元素,而元素的识别就是通过HTML的标签和属性,所以对于基本的HTML的只是是必备的 随着页面复杂度的提升,加之很多公司的开发也没有统一规范,这就给识别元素造成了非常 ...
- 【遍历二叉树】12往二叉树中添加层次链表的信息【Populating Next Right Pointers in Each Node II】
本质上是二叉树的层次遍历,遍历层次的过程当中把next指针加上去. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- CodeForces - 1017 C. The Phone Number(数学)
Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number! The ...
- 2017.10.6北京清北综合强化班DAY6
题目大意:改变一个数的位置 把一个序列变成不下降序列 题解: 设置一个pre,如果破坏单调性,就把‘删除’这个.否则把pre修改为当前元素的值. 考试时这样得了90分,是因为我的做法只能过这样的数据 ...
- 系列文章--8天学通MongoDB
随笔分类 - MongoDB 8天学通MongoDB——第八天 驱动实践 摘要: 作为系列的最后一篇,得要说说C#驱动对mongodb的操作,目前驱动有两种:官方驱动和samus驱动,不过我个人还是喜 ...
- HBase的bulkLoad
HBase的BulkLoad有两种方式: thinrow的机制是flatmap把cell的信息进行flatmap:适合少于1万列的数据集:thinrow的涵义就是少行多列: bulkload的机制则是 ...