zoukankan      html  css  js  c++  java
  • 常用算法

    #常用算法竞赛头文件及宏定义:

    1 #include <iostream>
    2 #include <algorithm>
    3 #include <cmath>
    4 #include <cstring>
    5 #define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);//将cin和cout的速率提升 6 using namespace std; 7 typedef long long ll;
    #include <bits/stdc++.h>//包含所有常用

    求取一个数的因子数目的算法:

     1 ll get(ll x) {
     2     ll sum = 0, sq = sqrt(x);    //开方,降低复杂度
     3     for (ll i = 1; i <= sq; i++) {
     4         if (x % i == 0) {
     5             sum += 2;
     6         }
     7     }
     8     if (sq * sq == x) {
     9         sum--;
    10     }
    11     return sum;
    12 }

    求最大公约数:

    1  int gcd(int x,int y){
    2              if(y==0){
    3                  return x;
    4              } else {
    5                  return gcd(y,x%y);
    6              }
    7          }
    8  

    从大到小排序:

    sort(A, A + n,greater<int>());

    二维数组初始化;

      

    vector<vector<int>> dp(N, vector<int>(N, -1));

     

  • 相关阅读:
    筱玛的迷阵探险(折半搜索+01字典树)
    递推
    thin mission 2021 10 8
    4级 -- 阅读
    c++——小知识
    stl
    string
    ting mission 2021.9.20
    ting mission 2021.9.27
    欧拉函数
  • 原文地址:https://www.cnblogs.com/DengSchoo/p/12312569.html
Copyright © 2011-2022 走看看