P1932 A+B A-B A*B A/B A%B Problem

题目背景

这个题目很新颖吧!!!

题目描述

求A、B的和差积商余!

由于数据有修改,减法运算结果可能带负号!

输入输出格式

输入格式:

两个数两行

A B

输出格式:

五个数

和 差 积 商 余

输入输出样例

输入样例#1: 复制

1
1
输出样例#1: 复制

2
0
1
1
0

说明

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的更多相关文章

  1. 【洛谷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[传送门](真是个优秀的高精) 算法:::::::(模板题弄这么费 ...

  2. [洛谷OJ] P1114 “非常男女”计划

    洛谷1114 “非常男女”计划 本题地址:http://www.luogu.org/problem/show?pid=1114 题目描述 近来,初一年的XXX小朋友致力于研究班上同学的配对问题(别想太 ...

  3. 洛谷1439 排列LCS问题

    洛谷1439 排列LCS问题 本题地址:http://www.luogu.org/problem/show?pid=1439 题目描述 给出1-n的两个排列P1和P2,求它们的最长公共子序列. 输入输 ...

  4. 洛谷1640 bzoj1854游戏 匈牙利就是又短又快

    bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...

  5. 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.

    没有上司的舞会  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...

  6. 洛谷P1108 低价购买[DP | LIS方案数]

    题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...

  7. 洛谷 P2701 [USACO5.3]巨大的牛棚Big Barn Label:二维数组前缀和 你够了 这次我用DP

    题目背景 (USACO 5.3.4) 题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N ...

  8. 洛谷P1710 地铁涨价

    P1710 地铁涨价 51通过 339提交 题目提供者洛谷OnlineJudge 标签O2优化云端评测2 难度提高+/省选- 提交  讨论  题解 最新讨论 求教:为什么只有40分 数组大小一定要开够 ...

  9. 洛谷P1371 NOI元丹

    P1371 NOI元丹 71通过 394提交 题目提供者洛谷OnlineJudge 标签云端评测 难度普及/提高- 提交  讨论  题解 最新讨论 我觉得不需要讨论O long long 不够 没有取 ...

随机推荐

  1. long long 与 __int64

    1.long long VC中不能用,codeblocks中 可以 #include<iostream> #include<stdio.h> using namespace s ...

  2. 有關WCF一個自認爲比較經典的博客

    无废话WCF入门教程四[WCF的配置文件] (http://www.cnblogs.com/iamlilinfeng/archive/2012/10/02/2710224.html) -------- ...

  3. python 链接sharepoint 2013 REST api

    import requests,simplejson from requests_ntlm import HttpNtlmAuth p1 = requests.get("http://you ...

  4. hbase_异常_01_Hbase: Failed to become active master

    一.异常现象 启动hbase之后,抛出异常,异常信息如下: master.HMaster: Failed to become active master hbase java.net.ConnectE ...

  5. 关于ATML信号定义的理解-1

    1.XML中的类型标签: <xs:complexType>复合类型和<xs:simpleTyle>简单类型是数据结构类型,包含了各种类型的属性.可以被子类型继承,继承方式为&l ...

  6. windows 安装 pytorch

    之前都在服务器上跑pytorch,近来发现新版本可在windows上跑了,甚是开心. 环境: windows7  python3 无CPU 步骤: 1. 确保确保python版本在3.5.3/3.6. ...

  7. java中变量的分类

    •按被声明的位置划分: –成员变量:方法外部.类的内部定义的变量 –局部变量:方法或语句块内部定义的变量        –注意:类外面(类对应的大括号外面)不能有变量的声明 •按所属的数据类型划分: ...

  8. I.MX6 Android 永不休眠

    /************************************************************************* * I.MX6 Android 永不休眠 * 说明 ...

  9. Mybatis学习--动态SQL

    学习笔记,选自Mybatis官方中文文档:http://www.mybatis.org/mybatis-3/zh/dynamic-sql.html MyBatis 的强大特性之一便是它的动态 SQL. ...

  10. hdu2196 Computer待续

    #include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #i ...