每逢大整数四则运算,都会怯懦,虽是算法竞赛必会的东西,也零散的学过,简单的总结过,但不成体系的东西心里一直没底。

所以今天消耗了大量的卡路里,啃了几套模板之后终于总结成了一套自己的模板

再也不用担心大整数啦

基础

1. 高精度加法

高精度加法等同于算术加法,做单个的加法运算之后存下进位

  • A和B都为正整数
  • vector中下标为0存的是低位(以下都是)
  1. vector<int> add(vector<int> &A,vector<int> &B){
  2. if(A.size() < B.size()) return add(B,A);//这是为了保证A的位数比B大
  3. vector<int> C;
  4. int t = 0;
  5. for(int i = 0;i < A.size();i++){
  6. t += A[i];
  7. if(i < B.size()) t += B[i];
  8. C.push_back(t % 10);
  9. t /= 10;
  10. }
  11. if(t) C.push_back(t);
  12. //清除前缀0,为了防止000+0等输入情况
  13. while(C.size() > 1 && C.back() == 0)C.pop_back();
  14. return C;
  15. }

2. 高精度减法

减法同加法原理一样,也是计算一位,下面用了t这个变量存下向更高一位借的1

  • A和B必须为正整数,结果返回|A-B|
  1. vector<int> sub(vector<int> &A,vector<int> &B){
  2. vector<int> C;
  3. for(int i= 0,t = 0;i<A.size();i++){
  4. t = A[i] - t;
  5. if(i < B.size()) t -= B[i];
  6. C.push_back((t+10)%10);
  7. if(t < 0) t = 1;
  8. else t = 0;
  9. }
  10. //清除前缀0
  11. while(C.size() > 1 && C.back() == 0)C.pop_back();
  12. return C;
  13. }

3. 高精度乘低精度

高精度的每一位与低精度数字进行相乘,因为相乘最大为81,所以结果对10取余得到的数字就是结果在当前位的结果,然后对结果除以10保存更高一位的进位数字

  • A存放正整数,b也为正整
  1. vector<int> mul(vector<int> &A,int b){
  2. vector<int> C;
  3. int t = 0;
  4. for(int i = 0;i < A.size() || t; i++){
  5. if(i < A.size()) t += A[i] * b;
  6. C.push_back(t%10);
  7. t /= 10;
  8. }
  9. return C;
  10. }

4. 高精度除以低精度

在计算除法时,会从被除数的最高位算起,每一位的计算结果就是当前余数对除数做除法的结果。然后计算下一位(更小的一位,设第x位)时,要更新余数即 余数*10 + 被除数的x位。

  • A 存放正整数,b也为正整数,r为余数
  1. vector<int> div(vector<int> & A,int b,int &r){
  2. vector<int> C;
  3. r = 0;
  4. for(int i = A.size() - 1;i >= 0;i--){
  5. r = r * BASE + A[i];
  6. C.push_back(r/b);
  7. r %= b;
  8. }
  9. reverse(C.begin(),C.end());
  10. while(C.size() > 1 && C.back() == 0)C.pop_back();
  11. return C;
  12. }

什么?乘低精度还不够?除低精度太low?那我们考虑一些不太常见的情况(openjudge百炼2980)

5. 高精度乘高精度

首先说一下乘法计算的算法,从低位向高位乘,在竖式计算中,我们是将乘数第一位与被乘数的每一位相乘,记录结果之后,用第二位相乘,记录结果并且左移一位,以此类推,直到计算完最后一位,再将各项结果相加,得出最后结果。

​ 计算的过程基本上和小学生列竖式做乘法相同。为了编程方便,并不急于处理进位,而是先将所有位上的结果计算之后,再从前往后以此处理进位。

​ 总结一个规律: 即一个数的第i 位和另一个数的第j 位相乘所得的数,一定是要累加到结果的第i+j 位上。这里i, j 都是从数字低位开始从0 开始计数。

ans[i+j] = a[i]*b[j];

​ 另外注意进位时要处理,当前的值加上进位的值再看本位数字是否又有进位;前导清零。

  1. vector<int> mul( vector<int> &A, vector<int> &B) {
  2. int la = A.size(),lb = B.size();
  3. vector<int> C(la+lb+10,0);//提前申请结果所需的空间
  4. for(int i=0;i<la;i++){
  5. for(int j=0;j<lb;j++){
  6. C[i+j] += A[i] * B[j];
  7. }
  8. }
  9. for(int i=0;i<C.size();i++){
  10. if(C[i] >= 10){
  11. C[i + 1] += C[i] / 10;
  12. C[i] %= 10;
  13. }
  14. }
  15. //处理前导0
  16. while(C.size() > 1 && C.back() == 0)C.pop_back();
  17. return C;
  18. }

6. 高精度除以高精度

大数除法是四则运算里面最难的一种。不同于一般的模拟,除法操作不是模仿手工除法,而是利用减法操作来实现的。其基本思想是反复做减法,看从被除数里面最多能减去多少个除数,商就是多少。逐个减显然太慢,要判断一次最多能减少多少个整数(除数)的10的n次方。

以7546除以23为例:

​ 先用7546减去23的100倍,即减去2300,可以减3次,余下646,此时商就是300 (300=100*3);

​ 然后646减去23的10倍,即减去230,可以减2次,余下186,此时商就是320 (320=300+10*2);

​ 然后186减去23,可以减8次,余下2,此时商就是328 (328=320+1*8);

​ 因为2除以23的结果小于1,而我们又不用计算小数点位,所以不必再继续算下去了。

计算结果中没有小数:

  1. vector<int> div(vector<int> A,vector<int> B){
  2. int la = A.size(),lb = B.size();
  3. int dv = la - lb; // 相差位数
  4. vector<int> C(dv+1,0);//提前申请结果所需空间
  5. //将除数扩大,使得除数和被除数位数相等
  6. reverse(B.begin(),B.end());
  7. for(int i=0;i<dv;i++)B.push_back(0);
  8. reverse(B.begin(),B.end());
  9. lb = la;
  10. for(int j=0;j<=dv;j++){
  11. while(!cmp(A,B)){//这里用到一个比较函数,cmp返回的是A是否比B小,此处判断的是A是否大于等于B,该循环当A无法再进行减法时结束
  12. A = sub(A,B);
  13. C[dv-j]++;//答案里相应的那一位数字++
  14. }
  15. B.erase(B.begin());//缩小被除数
  16. }
  17. while(C.size()>1 && C.back() == 0)C.pop_back();
  18. return C;
  19. }

好了,基础部分到此结束,将上面的内容封装好之后,我们就可以比较完美的在比赛中使用了。

综合

  • 该结构体是借用紫书上的模板,BASE是数组一位上面可以存数的值。也可以理解为是一个BASE进制数,WIDTH对应的是BASE的宽度
  • 因为大整数乘大整数所用计算方法的特殊性,BASE应当设置为10,WIDTH设置为1,相应的重载输出流里面的sprinf函数中也应该控制为1位而不是8位
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. struct BigInteger{
  5. //BASE为vector数组中一位中最大存储的数字,前面都是以10计算的
  6. //WIDTH为宽度
  7. static const int BASE = 10000;
  8. static const int WIDTH = 4;
  9. vector<int> s;
  10. //正数为1,负数为-1
  11. int flag = 1;
  12. //构造函数
  13. BigInteger(int num = 0){*this = num;}
  14. BigInteger(string str){*this = str;}
  15. BigInteger(const BigInteger& t){
  16. this->flag = t.flag;
  17. this->s = t.s;
  18. }
  19. //赋值函数
  20. BigInteger operator = (int num){
  21. s.clear();
  22. do {
  23. s.push_back(num % BASE);
  24. num /= BASE;
  25. }while(num > 0);
  26. return *this;
  27. }
  28. BigInteger operator = (string &str){
  29. s.clear();
  30. int x,len = (str.length()-1)/WIDTH + 1;
  31. for(int i=0;i<len;i++){
  32. int end = str.length() - i*WIDTH;
  33. int start = max(0,end - WIDTH);
  34. sscanf(str.substr(start,end-start).c_str(),"%d",&x);
  35. s.push_back(x);
  36. }
  37. return *this;
  38. }
  39. //基本比较函数 A < B
  40. bool cmp( vector<int> &A, vector<int> & B){
  41. if(A.size() != B.size())return A.size() < B.size();
  42. for(int i=A.size()-1;i>=0;i--){
  43. if(A[i] != B[i]){
  44. return A[i] < B[i];
  45. }
  46. }
  47. return false;
  48. }
  49. //比较函数如果小于则返回真
  50. bool operator < ( BigInteger & b){
  51. return cmp(s,b.s);
  52. }
  53. bool operator > ( BigInteger& b){
  54. return b < *this;
  55. }
  56. bool operator <= ( BigInteger &b){
  57. return !(b < *this);
  58. }
  59. bool operator >= ( BigInteger &b){
  60. return !(*this < b);
  61. }
  62. bool operator == ( BigInteger &b){
  63. return !(b < *this) && (*this < b);
  64. }
  65. //基本四则运算
  66. vector<int> add(vector<int> &A, vector<int> &B);
  67. vector<int> sub(vector<int> &A, vector<int> &B);
  68. vector<int> mul(vector<int> &A, int b);
  69. vector<int> mul(vector<int> &A, vector<int> &B);
  70. vector<int> div(vector<int> &A, int b);
  71. vector<int> div(vector<int> A, vector<int> B);
  72. //重载运算符
  73. BigInteger operator + (BigInteger &b);
  74. BigInteger operator - (BigInteger &b);
  75. BigInteger operator * (BigInteger &b);
  76. BigInteger operator * (int b);
  77. BigInteger operator / (BigInteger & b);
  78. BigInteger operator / (int b);
  79. };
  80. //重载<<
  81. ostream& operator << (ostream &out,const BigInteger& x) {
  82. if(x.flag == -1)out << '-';
  83. out << x.s.back();
  84. for(int i = x.s.size() - 2; i >= 0;i--){
  85. char buf[20];
  86. sprintf(buf,"%04d",x.s[i]);//08d此处的8应该与WIDTH一致
  87. for(int j=0;j<strlen(buf);j++)out<<buf[j];
  88. }
  89. return out;
  90. }
  91. //重载输入
  92. istream& operator >> (istream & in,BigInteger & x){
  93. string s;
  94. if(!(in>>s))return in;
  95. x = s;
  96. return in;
  97. }
  98. vector<int> BigInteger::add( vector<int> &A, vector<int> &B){
  99. if(A.size() < B.size())return add(B,A);
  100. int t = 0;
  101. vector<int> C;
  102. for(int i=0;i<A.size();i++){
  103. if(i<B.size())t += B[i];
  104. t += A[i];
  105. C.push_back(t%BASE);
  106. t /= BASE;
  107. }
  108. if(t)C.push_back(t);
  109. while(C.size() > 1 && C.back() == 0)C.pop_back();
  110. return C;
  111. }
  112. vector<int> BigInteger::sub( vector<int> &A, vector<int> &B){
  113. vector<int> C;
  114. for(int i=0,t=0;i<A.size();i++){
  115. t = A[i] - t;
  116. if(i<B.size())t -= B[i];
  117. C.push_back((t+BASE)%BASE);
  118. if(t < 0)t = 1;
  119. else t = 0;
  120. }
  121. while(C.size() > 1 && C.back() == 0)C.pop_back();
  122. return C;
  123. }
  124. vector<int> BigInteger::mul(vector<int> &A,int b){
  125. vector<int> C;
  126. int t = 0;
  127. for(int i = 0;i < A.size() || t; i++){
  128. if(i < A.size()) t += A[i] * b;
  129. C.push_back(t%BASE);
  130. t /= BASE;
  131. }
  132. return C;
  133. }
  134. //大数乘大数乘法需要将BASE设置为10,WIDTH设置为1
  135. vector<int> BigInteger::mul( vector<int> &A, vector<int> &B) {
  136. int la = A.size(),lb = B.size();
  137. vector<int> C(la+lb+10,0);
  138. for(int i=0;i<la;i++){
  139. for(int j=0;j<lb;j++){
  140. C[i+j] += A[i] * B[j];
  141. }
  142. }
  143. for(int i=0;i<C.size();i++){
  144. if(C[i] >= BASE){
  145. C[i + 1] += C[i] / BASE;
  146. C[i] %= BASE;
  147. }
  148. }
  149. while(C.size() > 1 && C.back() == 0)C.pop_back();
  150. return C;
  151. }
  152. //大数除以整数
  153. vector<int> BigInteger::div(vector<int> & A,int b){
  154. vector<int> C;
  155. int r = 0;
  156. for(int i = A.size() - 1;i >= 0;i--){
  157. r = r * BASE + A[i];
  158. C.push_back(r/b);
  159. r %= b;
  160. }
  161. reverse(C.begin(),C.end());
  162. while(C.size() > 1 && C.back() == 0)C.pop_back();
  163. return C;
  164. }
  165. //大数除以大数
  166. vector<int> BigInteger::div(vector<int> A,vector<int> B){
  167. int la = A.size(),lb = B.size();
  168. int dv = la - lb; // 相差位数
  169. vector<int> C(dv+1,0);
  170. //将除数扩大,使得除数和被除数位数相等
  171. reverse(B.begin(),B.end());
  172. for(int i=0;i<dv;i++)B.push_back(0);
  173. reverse(B.begin(),B.end());
  174. lb = la;
  175. for(int j=0;j<=dv;j++){
  176. while(!cmp(A,B)){
  177. A = sub(A,B);
  178. C[dv-j]++;
  179. }
  180. B.erase(B.begin());
  181. }
  182. while(C.size()>1 && C.back() == 0)C.pop_back();
  183. return C;
  184. }
  185. BigInteger BigInteger::operator + ( BigInteger & b){
  186. BigInteger c;
  187. c.s.clear();
  188. c.s = add(s,b.s);
  189. return c;
  190. }
  191. BigInteger BigInteger::operator - ( BigInteger & b) {
  192. BigInteger c;
  193. c.s.clear();
  194. if(*this < b){
  195. c.flag = -1;
  196. c.s = sub(b.s,s);
  197. }
  198. else{
  199. c.flag = 1;
  200. c.s = sub(s,b.s);
  201. }
  202. return c;
  203. }
  204. BigInteger BigInteger::operator *(BigInteger & b){
  205. BigInteger c;
  206. c.s = mul(s,b.s);
  207. return c;
  208. }
  209. BigInteger BigInteger::operator *(int b){
  210. BigInteger c;
  211. c.s = mul(s,b);
  212. return c;
  213. }
  214. BigInteger BigInteger::operator /(BigInteger & b){
  215. BigInteger c;
  216. if(*this < b){
  217. return c;
  218. }
  219. else{
  220. c.flag = 1;
  221. c.s = div(s,b.s);
  222. }
  223. return c;
  224. }
  225. BigInteger BigInteger::operator /(int b){
  226. BigInteger c;
  227. BigInteger t = b;
  228. if(*this < t){
  229. c.s.push_back(0);
  230. }
  231. else{
  232. c.flag = 1;
  233. c.s = div(s,b);
  234. }
  235. return c;
  236. }

另附数组实现版本,适合运算次数较多,但数字位数不太长的情况

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int inf = 0x3f3f3f3f;
  5. #define dbg(x...) do { cout << "\033[32;1m" << #x <<" -> "; err(x); } while (0)
  6. void err() { cout << "\033[39;0m" << endl; }
  7. template<class T, class... Ts> void err(const T& arg,const Ts&... args) { cout << arg << " "; err(args...); }
  8. const int N = 500 + 5;
  9. class BigInt{
  10. public:
  11. int a[N];
  12. int len;
  13. public:
  14. const int BASE = 10000;
  15. const int WIDTH = 4;
  16. void mem(){memset(a, 0, sizeof a);}
  17. void adjust(){while(len > 1 && a[len-1] == 0) len--;}
  18. public:
  19. BigInt(){len = 1; mem();}
  20. BigInt(const int);
  21. BigInt(const char*);
  22. BigInt(const BigInt&);
  23. public:
  24. friend istream& operator >> (istream&, BigInt&);
  25. friend ostream& operator << (ostream&, BigInt&);
  26. public:
  27. BigInt operator = (const BigInt &) ;
  28. BigInt operator + (const BigInt &) const;
  29. BigInt operator - (const BigInt &) const;
  30. BigInt operator * (const BigInt &) const;
  31. BigInt operator * (const int &) const;
  32. BigInt operator / (const int &) const;
  33. BigInt operator ^ (const int &) const;
  34. public:
  35. int operator % (const int &T) const;
  36. bool operator > (const BigInt &T) const;
  37. bool operator < (const BigInt &T) const;
  38. bool operator <= (const BigInt &T) const;
  39. bool operator >= (const BigInt &T) const;
  40. bool operator == (const BigInt &T) const;
  41. };
  42. BigInt::BigInt(const int b){
  43. int val = b;
  44. mem();
  45. len = 0;
  46. do {
  47. a[len++] = val % BASE;
  48. val /= BASE;
  49. } while(val);
  50. }
  51. BigInt::BigInt(const char *s){
  52. mem(); int l = strlen(s);
  53. int index = 0;
  54. for(int i=l-1;i>=0;i-=WIDTH){
  55. int t = 0;
  56. int k = i - WIDTH + 1;
  57. if(k < 0) k = 0;
  58. for(int j=k;j<=i;j++){
  59. t = t * 10 + s[j] - '0';
  60. }
  61. a[index++] = t;
  62. }
  63. len = index;
  64. adjust();
  65. }
  66. BigInt::BigInt(const BigInt&b){
  67. len = b.len;
  68. memcpy(a, b.a, sizeof a);
  69. }
  70. istream& operator >>(istream &in, BigInt &b){
  71. char s[N];
  72. in >> s;
  73. b = BigInt(s);
  74. return in;
  75. }
  76. ostream& operator <<(ostream &out, BigInt &b){
  77. printf("%d", b.a[b.len-1]);
  78. for(int i=b.len-2;i>=0;i--){
  79. printf("%04d", b.a[i]);
  80. }
  81. return out;
  82. }
  83. BigInt BigInt::operator = (const BigInt &b) {
  84. len = b.len;
  85. memcpy(a, b.a, sizeof a);
  86. return *this;
  87. }
  88. BigInt BigInt::operator + (const BigInt& b)const{
  89. BigInt res;
  90. res.len = max(len, b.len);
  91. int t = 0;
  92. for(int i=0;i<res.len;i++){
  93. if(i < len) t += a[i];
  94. if(i < b.len) t += b.a[i];
  95. res.a[i] = t % BASE;
  96. t /= BASE;
  97. }
  98. if(t) res.a[res.len++] = t;
  99. res.adjust();
  100. return res;
  101. }
  102. BigInt BigInt::operator - (const BigInt& b)const{
  103. BigInt res;
  104. for(int i = 0, t = 0;i < len; i++){
  105. t = a[i] - t;
  106. if(i < b.len) t -= b.a[i];
  107. res.a[i] = (t + BASE) % BASE;
  108. if(t < 0) t = 1;
  109. else t = 0;
  110. }
  111. res.len = len;
  112. res.adjust();
  113. return res;
  114. }
  115. BigInt BigInt::operator * (const BigInt& b)const{
  116. BigInt res;
  117. for(int i=0;i<len;i++){
  118. int up = 0;
  119. for(int j=0;j<b.len;j++){
  120. up = a[i] * b.a[j] + res.a[i+j] + up;
  121. res.a[i+j] = up % BASE;
  122. up = up / BASE;
  123. }
  124. if(up != 0) res.a[i+b.len] = up;
  125. }
  126. res.len = len + b.len;
  127. res.adjust();
  128. return res;
  129. }
  130. BigInt BigInt::operator * (const int &b) const{
  131. int t = 0;
  132. BigInt res;
  133. res.len = len;
  134. for(int i=0;i<len;i++){
  135. t = a[i] * b + t;
  136. res.a[i] = t % BASE;
  137. t /= BASE;
  138. }
  139. if(t) res.a[res.len++] = t;
  140. res.adjust();
  141. return res;
  142. }
  143. BigInt BigInt::operator / (const int &b)const{
  144. BigInt res;
  145. res.len = len;
  146. int i, down = 0;
  147. for(int i=len-1;i>=0;i--){
  148. down = down * BASE + a[i];
  149. res.a[i] = down / b;
  150. down %= b;
  151. }
  152. res.adjust();
  153. return res;
  154. }
  155. BigInt BigInt::operator ^ (const int &n)const{
  156. int i, d = 0;
  157. if(n<0) exit(-1);
  158. if(n == 0) return 1;
  159. if(n == 1) return *this;
  160. BigInt res = *this, t = *this;
  161. for(int b = n-1; b;b>>=1){
  162. if(b & 1) res = res * t;
  163. t = t * t;
  164. }
  165. return res;
  166. }
  167. int BigInt::operator%(const int &b)const{
  168. int i, d = 0;
  169. for(i=len-1;i>=0;i--){
  170. d = ((d * BASE) % b + a[i]) % b;
  171. }
  172. return d;
  173. }
  174. bool BigInt::operator > (const BigInt &T)const{
  175. if(len > T.len) return true;
  176. else if(len < T.len) return false;
  177. int ln = len - 1;
  178. while(a[ln] == T.a[ln] && ln>=0) ln--;
  179. if(ln >= 0 && a[ln] > T.a[ln]) return true;
  180. else return false;
  181. }
  182. bool BigInt::operator < (const BigInt &T)const{
  183. return T > *this;
  184. }
  185. bool BigInt::operator >= (const BigInt &T)const{
  186. return !(T > *this);
  187. }
  188. bool BigInt::operator <= (const BigInt &T)const{
  189. return !(*this > T);
  190. }
  191. bool BigInt::operator == (const BigInt&T)const{
  192. return !(*this > T) && !(T > *this);
  193. }
  194. int n;
  195. BigInt f[110];
  196. int main(){
  197. f[0] = 1;
  198. for(int i=1;i<=100;i++){
  199. f[i] = f[i-1] * (4 * i - 2) / (i + 1);
  200. }
  201. while(~scanf("%d", &n)){
  202. if(n == -1) break;
  203. cout << f[n] << endl;
  204. }
  205. return 0;
  206. }

总结

模板只提供了正整数的运算,对于含有负整数的运算,只需要进行合理的转换即可,见下表

A B + - * /
+ + |A|+|B| |A|-|B| |A|*|B| |A|/|B|
+ - |A|-|B| |A|+|B| -(|A|*|B|) -(|A|/|B|)
- + |B|-|A| -(|A|+|B|) -(|A|*|B|) -(|A|/|B|)
- - -(|A|+|B|) |B|-|A| |A|*|B| |A|/|B|

【附:参考资料】

  1. https://www.cnblogs.com/wuqianling/p/5387099.html
  2. ACwing算法基础课
  3. 算法竞赛入门经典
  4. 红宝书

大整数四则运算(vector与数组两种版本实现)的更多相关文章

  1. 【转载】pygame安装与两种版本的Python兼容问题

    在开始学习游戏编程之前,我们先来安装下pygame和python3.2.5 参考园友: http://www.cnblogs.com/hongten/p/hongten_pygame_install. ...

  2. Code Kata:大整数比较大小&大整数四则运算---加减法 javascript实现

    大整数的四则运算已经是老生常谈的问题了.很多的库也已经包含了各种各样的解决方案. 作为练习,我们从最简单的加减法开始. 加减法的核心思路是用倒序数组来模拟一个大数,然后将两个大数的利用竖式进行运算. ...

  3. Code Kata:大整数四则运算—除法 javascript实现

    除法不可用手工算法来计算,其基本思想是反复做减法,看从被除数里面最多能减去多少个除数,商就是多少. 除法函数: 如果前者绝对值小于后者直接返回零 做减法时,不需要一个一个减,可以以除数*10^n为基数 ...

  4. Code Kata:大整数四则运算—乘法 javascript实现

    上周练习了加减法,今天练习大整数的乘法运算. 采取的方式同样为竖式计算,每一位相乘后相加. 乘法函数: 异符号相乘时结果为负数,0乘任何数都为0 需要调用加法函数 因为输入输出的为字符串,需要去除字符 ...

  5. 矩阵或多维数组两种常用实现方法 - python

    在python中,实现多维数组或矩阵,有两种常用方法: 内置列表方法和numpy 科学计算包方法. 下面以创建10*10矩阵或多维数组为例,并初始化为0,程序如下: # Method 1: list ...

  6. 手把手教你如何安装Tensorflow(Windows和Linux两种版本)

    tensorflow 不支持Python2.7,最好选择下载Python3.5 现在越来越多的人工智能和机器学习以及深度学习,强化学习出现了,然后自己也对这个产生了点兴趣,特别的进行了一点点学习,就通 ...

  7. Tensorflow从0到1(一)之如何安装Tensorflow(Windows和Linux两种版本)

    现在越来越多的人工智能和机器学习以及深度学习,强化学习出现了,然后自己也对这个产生了点兴趣,特别的进行了一点点学习,就通过这篇文章来简单介绍一下,关于如何搭建Tensorflow以及如何进行使用.建议 ...

  8. OC动态创建的问题变量数组.有数组,在阵列13要素,第一个数据包阵列,每3元素为一组,分成若干组,这些数据包的统一管理。最后,一个数组.(要动态地创建一个数组).两种方法

    <span style="font-size:24px;">//////第一种方法 //        NSMutableArray *arr = [NSMutable ...

  9. OC中动态创建可变数组的问题.有一个数组,数组中有13个元素,先将该数组进行分组,每3个元素为一组,分为若干组,最后用一个数组统一管理这些分组.(要动态创建数组).两种方法

    <span style="font-size:24px;">//////第一种方法 // NSMutableArray *arr = [NSMutableArray a ...

随机推荐

  1. 如何优雅的传递 stl 容器作为函数参数来实现元素插入和遍历?

    问题背景 开始正文之前,做一些背景铺垫,方便读者了解我的工程需求.我的项目是一个客户端消息分发中心,在连接上消息后台后,后台会不定时的给我推送一些消息,我再将它们转发给本机的其它桌面产品去做显示.后台 ...

  2. 万万没想到,JVM内存区域的面试题也可以问的这么难?

    二.Java内存区域 1.Java内存结构 内存结构 程序计数器 当前线程所执行字节码的行号指示器.若当前方法是native的,那么程序计数器的值就是undefined. 线程私有,Java内存区域中 ...

  3. Pandas数据分析练手题(十题)

    数据集下载地址:https://github.com/Rango-2017/Pandas_exercises --------------------------------------------- ...

  4. 【Linux】Linux介绍和安装 - 测试题

    第一部分测试题 Linux介绍和安装 测试题 做点练习题,巩固一下咯~ ~ _ 10 个选择题. 1.让我们选择开机时进哪个操作系统的软件叫什么? A. booter B. bootloader C. ...

  5. 鸿蒙的多媒体及Menu组件及小程序的多媒体组件

    目录: js业务逻辑层 视图渲染层 css属性设置 效果图 微信小程序展示 内网穿透工具下载 我们在搭建一个小程序或者网站的时候,往往要加载很多的图片,音频和视频文件.如果都从服务器获取静态资源,这样 ...

  6. Tensorflow-线性回归与手写数字分类

    线性回归 步骤 构造线性回归数据 定义输入层 设计神经网络中间层 定义神经网络输出层 计算二次代价函数,构建梯度下降 进行训练,获取预测值 画图展示 代码 import tensorflow as t ...

  7. cisco思科交换机终端远程ssh另一端报错:% ssh connections not permitted from this terminal

    故障现象: XSJ-GH10-C3750->ssh 58.64.xx.xx% ssh connections not permitted from this terminal 解决办法: 原因: ...

  8. Docker部署SayHello(FastAPI)

    目录 前言 服务部署 部署后端 1. 进入到sayhello目录 2. 编写API的Dockerfile(如果有请之直接构建镜像- 在下一步) 3. 构建镜像 4. 运行容器 5. 访问IP:8000 ...

  9. Property attribute.

    class property(object): """ Property attribute. fget function to be used for getting ...

  10. (Mysql)连接问题之1130

    访问远程服务器上的Mysql数据库连接是报:1130-host is not allowed to connect this MYSQL severe; 解决方案: 登录远程服务器下的mysql下. ...