一) 1s 可以运算1e8~5e8次
二) 等差数列
1.for O(n)
for(i=0;i<n;i++){
s++;
2.((1+n)n)/2 O(1)
3.n+n/2+n/3+n/4+…+n/n O(nlog(n))
for(i=0;i<n;i++)
for(j=0;j<n;j=+i)
s++;
三)数组
动态数组 | vector< int> a |
---|---|
数据长度 | a.size() |
新增元素 | a.push_back(123) |
删除元素 | a.pop_back() |
访问 | a[i] |
#include<bits/stdc++.h>
using namespace std;
vector<int> a;//动态数组
int main(){
//a.size()获取数据长度
cout << a.size() <<endl //\n
//新增元素,在数组后面
a.push_back(123);
//删除一个元素
a.pop_back();
//访问 a[i]
int n = a.size();
for(int i = 0 ;i<n;i++){
cout << a[i] <<" ";
}
//增强性for
for(auto g :a){
cout << g <<" ";
}
return 0;
}
四)队列
队列 | queue< int> a |
---|---|
大小 | a.size() |
队头删除 | a.pop() |
访问队头 | a.front() |
访问队尾 | a.back() |
#include <bits/stdc++.h>
using namespace std;
queue< int> a;
int main(){
//大小
cout << a.size() <<endl;
//队尾新增
a.push(10);
//队头删除
a.pop();
//访问队头
a.front();
//访问队尾
a.back();
return 0;
}
五)栈
栈 | stack< int> s |
---|---|
大小 | s.size() |
新增 | s.push(5) |
删除 | s.pop() |
访问 | s.top() |
#include <bits/stdc++.h>
using namespace std;
stack<int> s;
int main(){
//大小
cout << s.size() <<end1;
//新增
s.push(5);
//删除
s.pop();
//访问
s.top();
return 0;
}
六)字符串
字符串 | string a |
---|---|
数组大小 | a.size() |
拼接 | b+c d+=‘x’ |
翻转字符串 | reverse(d.begin(),d.end()) |
寻找子串 | a.find(b) == string::npos |
#include <bits/stdc++.h>
using namespace std;
string a="666";
int main(){
cout << a.size() <<endl;
string b = "123";
string c ="456";
//拼接
string d = b+c;
cout <<d <<endl;
char x ='x';
d +=x;
d += 'x';
d.push_back('x');
cout <<d <<endl;
reverse(d.begin(),d.end());
cout <<d <<endl;
//寻找子串
string str = "abcdxx";
string b;
while(cin >>b){
if(a.find(b) == string::npos) cout <<"No" <<denl;
else cout <<"Yes" <<endl;
}
return 0;
}
七)memset
ps:只能初始化0 || -1
memset(dp , -1 , sizeof dp);// 把所有dp置为-1