博客
关于我
高精度:大数相除
阅读量:177 次
发布时间:2019-02-28

本文共 989 字,大约阅读时间需要 3 分钟。

数据范围

1≤A的长度≤100000,
1≤B≤10000
输入样例:
7
2
输出样例:
3
1

思路:其实都一样的,利用我们的人工模拟除法思维,虽然做除法时从高位开始存会比较方便,但为了模板和加减发一样更便于记忆,任然可以从低位开始存,只不过结果稍微处理一下就好。(我也不想说什么了,明明我的代码没有问题,但但它的测评器输出的商和余数的顺序就是反对,就是不让我过,,,orz)。

代码实现

#include
using namespace std;#define rep(i,a,n) for(int i=a;i<=n;i++)typedef long long ll;const int INF=0x3f3f3f3f;const int MAXN=2e5+5;//A / b,商是C,余数是rvector
div(vector
&A, int b, int &r){ vector
C; r = 0; for(int i = A.size() - 1; i >= 0; i -- ){ r = r * 10 + A[i]; C.push_back(r / b); r %= b; } reverse(C.begin(), C.end()); while(C.size() > 1 && C.back() == 0 ) C.pop_back();//去前导0 return C;}int main(){ string a; int b, r; vector
A; cin >> a >> b; for(int i = a.size() - 1; i >= 0; i -- ) A.push_back(a[i] - '0'); vector
C = div(A, b, r); for(int i = C.size() - 1; i >= 0; i -- ) printf("%d", C[i]); cout << endl << r << endl; return 0;}

转载地址:http://ubdj.baihongyu.com/

你可能感兴趣的文章
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>