temp

  • 頭文件
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cctype>
#include<numeric>
#include<vector>
#include<queue>
#include<map>
#include<set>
  • memset函數(shù)(vector數(shù)組不可用)
#include<cstring>

int a[100];
memset(a,0,sizeof(a));
  • memcpy函數(shù)(vector數(shù)組不可用)
#include <iostream>
#include<cstring>
using namespace std;
int main()
{
    int b[6]={2,3,1,4,6,5},a[6];
    memcpy(a,b,sizeof(b));//memcpy(a,b,6)這種寫法是錯誤的!
    for(int i=0;i<6;i++)
    {
       cout<<a[i]<<" ";//2 3 1 4 6 5
    }
    return 0;
}

vector

  • 錯誤寫法
vector<double> cou_aver;
cou_aver[j]+=score;
  • sort函數(shù)
//vc為vector類型
sort(vc.begin(),vc.end(),cmp);
  • 刪除最后一個元素
vc.pop_back();
  • 自動求和
#include<numeric>

int sum=accumulate(vc.begin(),vc.end(),0);
    #include<algorithm>

    int arr[10]={12,4,6,8,3,1};//不要寫6
    sort(arr,arr+3);//對arr的前三個元素進行排序,默認升序
    for(int i=0;i<6;i++)
    {
        cout<<arr[i]<<" ";//4 6 12 8 3 1
    }
  • 每月天數(shù)
int each[12]= {31,28,31,30,31,30,30,31,30,31,30,31};
  • 判斷閏年
bool IfRun(int n)
{
    if(n%100==0)
    {
        if(n%400==0)
            return true;
    }
    else
    {
        if(n%4==0)
            return true;
    }
    return false;
}
  • 判斷素數(shù)
bool isPrime(int n)
{
    if(n==1) //1不是素數(shù)
    return false;
    int sqr=(int)sqrt(1.0*n);
    for(int i=2;i<=sqr;i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
  • 獲取100以內(nèi)素數(shù),存于數(shù)組prime
#include <iostream>
#include<cstring>
using namespace std;
const int maxn=101;
int prime[maxn],pNum=0;
bool p[maxn];
void Find_Prime()
{
    for(int i=2;i<maxn;i++)
    {
        if(p[i]==false)
        {
            prime[pNum++]=i;
            for(int j=i+i;j<maxn;j+=i)
            {
                p[j]=true;
            }
        }
    }
}
int main()
{
    memset(p,false,sizeof(p));
    Find_Prime();
    for(int i=0;i<pNum;i++)
    {
        printf("%d ",prime[i]);
        //2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
    }
    return 0;
}
  • 將n進行質(zhì)因數(shù)分解,結(jié)果存于fac數(shù)組
//詳見算法筆記P168
#include <iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100010;
int prime[maxn],pNum=0;
bool p[maxn];
void Find_Prime()
{
    for(int i=2; i<maxn; i++)
    {
        if(p[i]==false)
        {
            prime[pNum++]=i;
            for(int j=i+i; j<maxn; j+=i)
            {
                p[j]=true;
            }
        }
    }
}
struct factor
{
    int x;
    int cnt;
} fac[10];
int fNum=0;
void getFac(int n)
{
    int sqr=(int)sqrt(1.0*n);
    for(int i=0; i<pNum&&prime[i]<=sqr; i++)//在素數(shù)范圍內(nèi)查找質(zhì)因數(shù)
    {
        if(n%prime[i]==0)
        {
            fac[fNum].x=prime[i];
            fac[fNum].cnt=0;
            while(n%prime[i]==0)
            {
                fac[fNum].cnt++;
                n/=prime[i];
            }
            fNum++;
        }
        if(n==1)//終點1
            break;
    }
    if(n!=1)//終點2
    {
        fac[fNum].x=n;
        fac[fNum].cnt=1;
        fNum++;
    }
}
int main()
{
    memset(p,false,sizeof(p));
    Find_Prime();
    getFac(180);
    cout<<"對于180"<<endl;
    for(int i=0; i<fNum;i++)
    {
       cout<<"質(zhì)因子"<<fac[i].x<<"個數(shù)為"<<fac[i].cnt<<endl;
    }
    return 0;
}
/*
對于180
質(zhì)因子2個數(shù)為2
質(zhì)因子3個數(shù)為2
質(zhì)因子5個數(shù)為1
*/
  • 找一個數(shù)的約數(shù),存于divs數(shù)組
#include<iostream>
#include<cstring>
using namespace std;
int divs[100],dnum=0;
void getDiv(int n)
{
    memset(divs,0,100);
    for(int i=1; i<=n/2; i++)//是n/2,不是n
    {
        if(n%i==0)
        {
            divs[dnum]=i;
            dnum++;
        }
    }
}
int main()
{
    //這兩句用于重置dnum和divs,常用于while(cin>>n){}內(nèi)
    dnum=0;
    memset(divs,0,100);

    getDiv(220);
    cout<<220<<"的約數(shù)為";
    for(int j=0; j<dnum; j++)
    {
        cout<<divs[j]<<" ";
    }
    return 0;
}
//220的約數(shù)為1 2 4 5 10 11 20 22 44 55 110
//詳見算法筆記P185
#include<iostream>
#include<cstring>
using namespace std;
long long C(long long n,long long m)
{
    long long ans=1;//注意
    for(long long i=1;i<=m;i++)
    {
        ans*=(n-m+i)/i;
    }
    return ans;
}
int main()
{
    cout<<C(3,2)<<endl;//3
    return 0;
}
  • cmp函數(shù)
bool cmp(cal a,cal b)
{
    if(abs(a.val)!=abs(b.val))
        return abs(a.val)>abs(b.val);
    else if(a.row!=b.row)
        return a.row>b.row;
    else
        return a.col>b.col;
  • C的合法標識符
1.首字母不能以數(shù)字開頭
2.在字符串中,只能有字母,數(shù)字,下劃線
  • getline格式
while(cin>>n)
    {
        char c=getchar();//getchar()不能放在for循環(huán)里面
       for(int i=0;i<n;i++)
       {
           string str;
          getline(cin,str);
          cout<<str<<endl;
       }
    }
/*3
wqe rtr
sd ioio
sdssd*/
  • 關于ASCII碼

字母ASCII碼

A-Z:65~90
a-z:97~122
cout<<('a'-96)*100;//100
cout<<'b'-'a'+'A'//'B'
cout<<'a'-'A'//32
cout<<'A'+32//97
cout<<char('A'+32)//a

漢字ASCII碼

1.小于0
2.占兩個字節(jié)//一個字母占1個字節(jié)
    cin>>str;
    for(int i=0;i<str.length();i++)
    {
        cout<<str[i]-'0'<<" ";
    }
/*輸入:東風破
輸出:-98 -94 -117 -136 -113 -134
*/

str[i]>=65

string str;
cin>>str;
for(int i=0;i<str.length();i++)
    {
        if(str[i]>=97&&str[i]<=122)
            cout<<"s";
        if(str[i]>=65&&str[i]<=97)
            cout<<"b";
    }
    return 0
/*輸入:abcdeABCDE
輸出:sssssbbbbb
*/
  • substr()
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str1,str2;
    cin>>str1>>str2;
   /*str1.substr(1)表示從第1個位置開始,截取len-1個字符
     str1.substr(1,3)表示從第1個位置開始,截取3個字符*/
    cout<<str1.substr(1)<<" "<<str2.substr(1,3)<<endl;
    return 0;
}
/*
輸入:qwerty dfghjkl
輸出:werty fgh
*/
  • 字符轉(zhuǎn)數(shù)字
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    cin>>str;
    cout<<str[2]-'0';
    return 0;
}
/*
輸入:4567
輸出:6
*/
  • 數(shù)字轉(zhuǎn)字符串
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int num;
    cin>>num;
    cout<<to_string(num).substr(3,1);//不是to_String
}
/*
輸入:23412
輸出:1
*/
  • 字符串轉(zhuǎn)數(shù)字
#include <iostream>
#include <string>
using namespace std;
int main() {
 string str = "123";
 int a = stoi(str);
 cout << a;//123
 str = "123.44";
 double b = stod(str);//123.44
 cout << b;
 return 0;
}
  • 字符串中多個字符轉(zhuǎn)數(shù)字
#include<iostream>
#include<string>
#include<cctype>>
using namespace std;
int main()
{
    string str;
    cin>>str;
    string num;
    for(int i=0;i<str.length();i++)
    {
        if(isdigit(str[i]))
            num+=str[i];
    }
    cout<<stoi(num)<<endl;
    return 0;
}
/*輸入:sdasd824sdsd
輸出:824
*/
  • 輸入字符串

字符串帶空格

 string str;
 while(getline(cin,str))
 {
     cout<<str<<endl;
 }
/*
輸入:sdsd dsds
輸出:sdsd dsds
*/
    cin>>n;
    char c=getchar();
    for(int i=0; i<n; i++)
    {
        string str;
        getline(cin,str);
        cout<<str<<endl;
    }
/*
輸入:2
sdsd dsds
yu io io
輸出:
sdsd dsds
yu io io
*/

字符串不帶空格

    cin>>n;
    for(int i=0; i<n; i++)
    {
        string str;
        cin>>str;
        cout<<str<<endl;
    }
/*
輸入:2
sdsddsds
yuioio
輸出:
sdsddsds
yuioio
*/
  • 統(tǒng)計單詞個數(shù)(輸入數(shù)據(jù)只有一行)
#include<iostream>
#include<vector>
#include<string>
#include<stdio.h>
using namespace std;
int main()
{
    string word;
    vector<string> words;
    while(cin>>word)
    {
        words.push_back(word);
        char c=getchar();//利用getchar()判斷換行
        if(c=='\n')
            break;
    }
    int size=words.size();
    cout<<size<<endl;
    return 0;
}
/*you are my friend
  4*/
  • 統(tǒng)計單詞個數(shù)(輸入數(shù)據(jù)有多行,遇到#終止)
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
    string str;
    vector<string> words;
    while(getline(cin,str))
    {
        if(str[0]=='#')
            return 0;
        int count=0;
        bool new_w=false,still=false;
        for(int i=0; i<str.length(); i++)
        {
            if(str[i]!=' '&&new_w==false&&still==false)
            {
                count++;
                new_w=true;
                still=true;
            }
            else
            {
                if(str[i]!=' ')
                {
                    still=true;
                }
                else
                {
                    still=false;
                }
                new_w=false;
            }
        }
        cout<<count<<endl;
    }
    return 0;
}
/*輸入:             you              are     my  friend               */
/*輸出:4              
  • if(b)
int b=1;
   if(b)
    cout<<"b is not zero"<<endl;//輸出:b is not zero"
  • 最大公約數(shù)
//輾轉(zhuǎn)相除法
int gcd(int m,int n)
{
    if(!n)
        return m;
    else
        return gcd(n,m%n);
}
  • 最小公倍數(shù)(基于gcd)
int lcm(int m,int n)
{ 
    int res=gcd(m,n);
    return m/res*n;
}
long long convert(string n, long long radix) {
 long long sum = 0;
 int index = 0, temp = 0;
 for (auto it = n.rbegin(); it != n.rend(); it++) {
 temp = isdigit(*it) ? *it - '0' : *it - 'a' + 10;
 sum += temp * pow(radix, index++);
 }
 return sum;
}
10^9以內(nèi),用int型
10^10及以上,用long long型

數(shù)論

  • 計算只包含加法、減法和乘法的整數(shù)表達式除以正整數(shù)n的余數(shù),可以在每步計算之后對n取余,結(jié)果不變。
  • Lagrange 四平方定理: 任何一個正整數(shù)都可以表示成不超過四個整數(shù)的平方之和。
  • 質(zhì)因子結(jié)論:對于一個正整數(shù)n來說,如果它存在[2,n]范圍內(nèi)的質(zhì)因子,
    要么這些質(zhì)因子全部小于等于sqrt(n),要么只存在一個大于sqrt(n)的質(zhì)因子,而其余質(zhì)因子全部小于等于sqrt(n)。

幾何

  • 三角形ABC的面積

    假設向量AB=(bx,by);向量AC=(cx,cy);則S=(bxcy-cxby)/2;
    參考資料

多邊形可劃分為多個三角形

S=s1+s2+s3+...+sn;其中si計算方法同上

  • 按位右移運算符(>>)
將數(shù)據(jù)除以2^n(2的n次方)
    int sum=48>>3;
    cout <<sum<< endl;//6
  • 按位左移運算符(<<)
將數(shù)據(jù)乘以2^n(2的n次方)
    int sum=3<<3;
    cout <<sum<< endl;//24

while

 while(n>0)
    {
        while(num>0)
        {
            num--;
            n--;
        }
    }
    cout<<n<<endl;//-7
  • 輸出從數(shù)組num中從A到B的數(shù);
    每 10 個數(shù)字占 1 行,其間以空格分隔;
    但行末不得有多余空格。
/*
11 13 17 19 23 29 31 37 41 43
47 53 59 61 67 71 73 79 83 89
97 101 103
*/
for(int i=A-1;i<B;i++)
    {
    count++;
    count%=10;
    if(count!=0)
    {
        if(count!=1)
            cout<<" ";
        cout<<num[i];
    }
    else
        cout<<" "<<num[i]<<endl;
    }
  • 遞推:找f(n)=a.f(n-1)+b.f(n-2),n大于等于4
1133、1143、1207、1249、1267、1284、1290、1297、1396、1992、1995、1996、2013、2014、2044
2045、2046、2047、2050、2064、2065、2067、2068、2070、2077、2085、2151、2154、2160、2190
2501、2512、2563、2569、2709、2716

比如2045
n=1時,f(1)=3;
n=2時,f(2)=6;
n=3時,f(3)=6;
n=4時,f(4)=18;
n=5時,f(5)=30;
則令f(n)=a.f(n-1)+b.f(n-2),易得a=1,b=6;

//2045
#include<iostream>
using namespace std;
int main()
{
    long long a[51];
    a[1]=3;
    a[2]=6;
    a[3]=6;
    for(int i=4; i<=50; i++)
    {
        a[i]=a[i-1]+a[i-2]*2;
    }
    int n;
    while(cin>>n)
    {
     cout<<a[n]<<endl;
    }
    return 0;
}

比如2046

n=1時,f(1)=1;
n=2時,f(2)=2;
n=3時,f(3)=3;
n=4時,f(4)=5;
n=5時,f(5)=8;
則令f(n)=a.f(n-1)+b.f(n-2),易得a=1,b=1;
  • 錯排(2048,2049)
    錯排公式:Dn=(n-1)(Dn-1+Dn-2),其中D0=0,D1=0,D2=1,D3=2,
    錯排概率:Dn/n!
//2048
#include<iostream>
using namespace std;
int main()
{
    long long a[51];
    a[0]=0;a[1]=0;a[2]=1;a[3]=2;
    for(int i=4; i<=50; i++)
    {
        a[i]=(i-1)*(a[i-1]+a[i-2]);
    }
    int T;
    cin>>T;
    for(int j=0;j<T;j++)
    {
     int n;
     cin>>n;
     long long m=1;
     for(long long i=2;i<=n;i++)
     {
         m*=i;
     }
     printf("%.2f",a[n]*1.00/m*100);
     printf("%\n");
    }
    return 0;
}
  • 直線劃分平面,平行線劃分平面,折線劃分平面(2050)
如果是N條直線分割,有M個面,則 M=1+(1+N)*N/2
如果是N對平行直線分割,有M個面,則M=1+2*N*N
如果是N條折線分割,有M個面,則M=1+2*N*N-N
  • Hash與字符
#include<iostream>
#include<string>
using namespace std;
int Hash[200];//必須是200,注意Hash必須作為全局變量,不可設于main內(nèi)
int main()
{
    for(int i=0;i<26;i++)
    {
        Hash['A'+i]=i+1;
        Hash['a'+i]=-(i+1);
    }
    char c;
    int n;
    while(cin>>c>>n)
    {
        cout<<Hash[c]+n<<endl;
    }
    return 0;
}
/*
輸入:A 1
輸出:2
*/
  • swap函數(shù)
#include<iostream>
using namespace std;
int main()
{
    int a=1,b=2;
    swap(a,b);
    cout<<a<<b<<endl;
    return 0;
}
//輸出:2 1
  • min函數(shù)
#include<iostream>
using namespace std;
int main()
{
    cout<<min(3,4)<<endl;
    return 0;
}
//輸出:3
#include<iostream>
using namespace std;
int main()
{
    long long a,b,sum;
    while(scanf("%I64X%I64X",&a,&b))
    {
        sum=a+b;
        if(sum>=0)
            printf("%I64X\n",sum);
        else
            printf("-%I64X\n",-sum);
    }
    return 0;
}
/*
輸入:
+A -A
1A -9
-1A -12
1A -AA
輸出:
0
11
-2C
-90
*/
  • 求滿足方程x(x+1)=132的解
            int x=sqrt(132);

            if((x(x+1)==132)
              cout<<x<<endl;
  • string比char數(shù)組好用的多系列
PB1076 Wifi密碼 

  • 四舍五入為整數(shù)(智障vc6.0不支持)
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int res=round(4.8);
    cout<<res<<endl;
    return 0;//5
}
  • 向上/下取整
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
   int res1=floor(5.6);
   printf("%d ",res1);

   int res2=ceil(5.6);
   printf("%d\n",res2);
   return 0;
}
/*輸出:5 6*/
  • unordered_set
#include<iostream>
#include<unordered_set>
using namespace std;
int main()
{
     unordered_set<int> se;
     se.insert(2);
     se.insert(1);
     se.insert(3);
     se.insert(8);
     for(auto it=se.begin();it!=se.end();it++)
     {
         cout<<*it<<" ";//8 3 1 2
     }
}

str[i]類型判斷

#include<cctype>

if(isdigit(str[i]))//str[i]為數(shù)字
if(isalpha(str[i]))//str[i]為字母(不區(qū)分大小寫)
if(islower(str[i]))//str[i]為小寫字母
if(isupper(str[i]))//str[i]為大寫字母
  • 字符串,數(shù)組逆置
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str="abcde";
reverse(str.begin(), str.end());
int arr[4]={2,3,1,4};
reverse(arr, arr+4);
cout<<str<<endl;//edcba
for(int i=0;i<4;i++)
{
    cout<<arr[i]<<" ";////4132
}
return 0;
}

字符串,查找子串

#include<iostream>
#include<string>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    string str="abcdefgh";
    cout<<str.find("bc")<<endl;//1
    cout<<str.find("poi")<<endl;//4294967295,大于str.size()的一個值
    return 0;
}
  • 大整數(shù)相加
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string add(string s1, string s2) {
 string s = s1;
 int carry = 0;
 for (int i = s1.size() - 1; i >= 0; i--) {
 s[i] = (s1[i] - '0' + s2[i] - '0' + carry) % 10 + '0';//字符轉(zhuǎn)數(shù)字
 carry = (s1[i] - '0' + s2[i] - '0' + carry) / 10;
 }
 if (carry > 0) s = "1" + s;
 return s;
}
int main()
{
    string A;
    cin>>A;
    string B=A;
    reverse(A.begin(),A.end());
    cout<<add(A,B)<<endl;
    return 0;
}
/*輸入:9865298697593927335572439430173
輸出13575648040349264629530408355862*/
  • map<string,double>初值為false
#include<map>

int main()
{
    map<string,bool> mp;
    if(mp["abc"]==false)
    cout<<"false"<<endl;//false
    return 0;
}

  • HDOJ2060(題目看不懂)
#include <cstdio>
int main()
{
    int t,n,a,b,i;
    int s[6]={7,6,5,4,3,2};
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&n,&a,&b);   
        if(n<6)
        {
            for(i=0;i<n;i++)
            {
                a+=s[i];
            }
        }   
        else
        {
            a+=(n-6)*8+27;
        }
        if(a>=b)
        printf("Yes\n");
        else
        printf("No\n");
    }
    return 0;
}
  • 插入char數(shù)組
    cin>>n>>m;

    for(int i=0; i<n; i++)
    {
        char c=getchar();
        for(int j=0; j<m; j++)
        {
            cin>>c;
            if(c=='*')
                mat[i][j]=0;
            else
                mat[i][j]=1;
        }
    }

     for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
          cout<<mat[i][j]<<" ";
        }
        cout<<endl;
    }
/*輸入:5 5
.....
.*.*.
.*S*.
.***.
...T*
輸出:
1 1 1 1 1
1 0 1 0 1
1 0 1 0 1
1 0 0 0 1
1 1 1 1 0*/
  • vector復制
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> v1,v2;
int main()
{
    for(int i=9; i>0; i--)
    {
        v1.push_back(i);
    }

    v2=v1;

    for(int i=0;i<v2.size();i++)
    {
        cout<<v2[i]<<" ";//9 8 7 6 5 4 3 2 1
    }

    return 0;
}
  • 一維數(shù)組復制
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int A[3];
    int B[3];

    for(int i=0; i<3; i++)
    {
        int num;
        cin>>num;
        A[i]=num;
    }

    memcpy(B,A,sizeof(A));
    for(int i=0; i<3; i++)
    {
        cout<<B[i]<<" ";
    }
    return 0;
}
/*輸入:1 2 3
輸出: 1 2 3*/
  • 二維數(shù)組復制
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int A[3][3];
    int B[3][3];

    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            int num;
            cin>>num;
            A[i][j]=num;
        }
    }

    memcpy(B,A,sizeof(A));
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {

            cout<<" "<<B[i][j];
        }
        cout<<endl;
    }
    return 0;
}
/*輸入:1 2 3 4 5 6 7 8 9
輸出: 1 2 3
      4 5 6
      7 8 9*/
  • 全局變量不要作為函數(shù)參數(shù)
#include<iostream>
using namespace std;
int n=100;
void add(int m)
{
    m++;
}
int main()
{
    add(n);
    cout<<n<<endl;//100
}
#include<iostream>
using namespace std;
int n=100;
void add()
{
    n++;
}
int main()
{
    add();
    cout<<n<<endl;//101
}

不需要它出來->局部變量(main函數(shù)內(nèi)部),函數(shù)含該參數(shù)
需要它出來->設為全局變量,函數(shù)不含該參數(shù)

  • 遞歸函數(shù),不同層參數(shù)傳遞情況
/*我們將遞歸函數(shù)的執(zhí)行流程分為"進入本層"與"回到上層"
1.對于全局變量(禁止作為遞歸函數(shù)參數(shù)),
"進入本層"與"回到上層"的改變是全局的,線形的,回不去的
2.對于遞歸函數(shù)參數(shù),比如第5層index=19,執(zhí)行了deep(index*2),
那么在第6層index值為38,第六層結(jié)束后回到第5層index值為19*/
#include<iostream>
using namespace std;
int M=100;//M為全局變量
void deep(int index,int cnt)//index,cnt為遞歸函數(shù)參數(shù)
{
    if(index==2)
    {
      cnt*=10;
      M*=10;
      cout<<"進入本層,index,cnt,m值為"<<index<<" "<<cnt<<" "<<M<<endl;
      return;
    }
    deep(index*2,cnt);
     cout<<"回到上一層,,index,cnt值為"<<index<<" "<<cnt<<" "<<M<<endl;
}
int main()
{
    deep(1,1);
}
/*輸出:進入本層,index,cnt,M值為2,10,1000
       回到上一層,index,cnt,M值為1,1,1*/
  • 合理的遞歸函數(shù)結(jié)構
void deep(int a,int b)
{
     //主要操作,包括對遞歸函數(shù)參數(shù)變量的讀操作
    deep(a+1,b*10)//對遞歸函數(shù)參數(shù)變量的寫操作
    //不要寫任何遞歸函數(shù)參數(shù)變量的讀/寫操作
   /*vest[i][j]=*/
}
  • a的b次冪不要用pow(),精度嚴重不足
#include<iostream>
using namespace std;
int getPow(int a,int b)
{
    for(int i=1; i<b; i++)
    {
        a*=a;
    }
    return a;
}
int main()
{
      cout<<getPow(2,3)<<endl;//8
}

set刪除元素

#include<iostream>
#include<set>
using namespace std;
int main()
{
    set<int> se;
    for(int i=1;i<=8;i++)
    {
        se.insert(i);
    }
    se.erase(6);
    for(auto it=se.begin();it!=se.end();it++)
    {
        cout<<*it<<" ";
    }
    return 0;
}
//輸出:1 2 3 4 5 7 8

Dijkstra+DFS模板,見算法筆記P383,384

  • 如何生成一個隨機三位數(shù)
int randnum=rand()%900+100;
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 基本概念 類( class ) 實例/對象 ( object ) 實例變量/成員變量 ( ivar, instan...
    WesleyLien閱讀 542評論 0 1
  • 寫在前面的話 代碼中的# > 表示的是輸出結(jié)果 輸入 使用input()函數(shù) 用法 注意input函數(shù)輸出的均是字...
    FlyingLittlePG閱讀 3,237評論 0 9
  • 一、Python簡介和環(huán)境搭建以及pip的安裝 4課時實驗課主要內(nèi)容 【Python簡介】: Python 是一個...
    _小老虎_閱讀 6,353評論 0 10
  • 記住一切有結(jié)果的人都是次數(shù)的累積,汗水的堆積而成就的,而你現(xiàn)在要做的就是扎扎實實地去做每一件事情,去累積你的次數(shù),...
    達浪Dalang閱讀 179評論 0 0
  • App官方文檔 運用 NSAttributedString 的場景一般有兩類 titleTextAttribute...
    JaiUnChat閱讀 3,628評論 0 0

友情鏈接更多精彩內(nèi)容