洛谷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 不够 没有取 ...
随机推荐
- name lookup of 'res' changed for new ISO 'res' scoping
#include<iostream> using namespace std; int pow ( int val, int exp ); int main() { int val = 2 ...
- Jmete基础使用
1,jmeter下载与安装 Jmeter的运行需要JDK支持,所以需要先安装好jdk,并配置好环境变量: 下载地址:http://jmeter.apache.org/download_jmeter.c ...
- Android: 利用SurfaceView绘制股票滑动直线解决延迟问题
1.背景介绍 最近项目要绘制股票走势图,并绘制能够跟随手指滑动的指示线(Indicator)来精确查看股票价格和日期.如下图所示: 上图中的那条白色直线就是股票的指示线,用来跟随手指精确确定股票的时间 ...
- ffmpeg推流命令参数记录
列出我们本机的设备:ffmpeg -list_devices true -f dshow -i dummy .\ffmpeg -r 25 -f dshow -s 640*480 -i video=&q ...
- 如何使 vlc 支持 fdk-aac 编码(windows平台
可能是由于fdk-aac开源协议的原因,VLC默认是不支持fdk-aac编码的,fdk-aac 是非常优秀的AAC编码库,并且支持AAC-LD AAC-ELD, 对于要求低延迟的场景下很有用. 可以通 ...
- UVA11059 - Maximum Product
1.题目名称 Maximum Product 2.题目地址 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemi ...
- L1-039 古风排版(20 分)
中国的古人写文字,是从右向左竖向排版的.本题就请你编写程序,把一段文字按古风排版. 输入格式: 输入在第一行给出一个正整数N(<100),是每一列的字符数.第二行给出一个长度不超过1000的非空 ...
- [SPOJ-DISUBSTR]Distinct Substrings
vjudge 题意 给你一个串,求不同字串个数. \(n\le10^5\) sol 直接建SAM然后输出\(\sum_{i=1}^{tot}len[i]-len[fa[i]]\) code #incl ...
- JavaScript RegExp 正则表达式基础详谈
前言: 正则对于一个码农来说是最基础的了,而且在博客园中,发表关于讲解正则表达式的技术文章,更是数不胜数,各有各的优点,但是就是这种很基础的东西,如果我们不去真正仔细研究.学习.掌握,而是抱着需要的时 ...
- java代码throws异常
总结:抛出异常 package com.ds; //异常捕获 public class fdsg { private static void throwException() { try { Stri ...