-
个人简介
private://私有 public://公开
#include<iostream> using namespace std; class animal{ private: int weight; public: void eat(){ cout<<"animal eat\n"; weight+=4; } void show(){ cout<<"animal weight"<<weight<<"\n"; } }; struct dog : public animal{ }; //多态 swap sort template<class T> void SWAP(T& a,T& b){ T t = a; a = b; b = t; } int main(){ /********1************/ int a1=10,b1=100; SWAP(a1,b1); cout<<a1<<" "<<b1<<"\n"; /********2************/ double a2=10.2,b2=100.5; SWAP(a2,b2); cout<<a2<<" "<<b2<<"\n"; /********3************/ string a3="10.2",b3="100.5"; SWAP(a3,b3); cout<<a3<<" "<<b3<<"\n"; animal an; an.eat(); //an.weight=100; //cout<<an.weight<<endl; dog hsp; hsp.eat(); hsp.show(); return 0; }
#include<bits/stdc++.h> using namespace std; struct shi{ int id; int o; }a[100001]; bool cmp(shi a,shi b){ return a.o<b.o; } int n,m,q,j=0; int main(){ //freopen("C.in","r",stdin); //freopen("C.out","w",stdout); int mid; int l,r; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i].o; a[i].id=i; } sort(a+1,a+n+1,cmp); for(int z=1;z<=m;z++){ cin>>q; l=1; r=n; while(l<=r){ mid=(l+r)/2; if(a[mid].o>q) r=mid-1; else if(a[mid].o<q) l=mid+1 ; else{ cout<<q<<" found at "<< mid<<"\n"; j=1; break; } }
if(j==0) cout<<q<<" not found\n"; j=0; } return 0;
}
//图有向图 #include<iostream> #include<cstdio> using namespace std; int vex[1024]={},n,m,v1,v2,q; struct node{int to;int next;int q;}edge[1024]; int main(){ cin>>n>>m; //创建邻接表开始 for(int i=1;i<=m;i++){ cin>>v1>>v2>>q; edge[i].to=v2; edge[i].q=q; edge[i].next=vex[v1]; vex[v1]=i; } //创建邻接表结束 //邻接表遍历开始 for(int i=1;i<=n;i++){//枚举所有顶点 printf("%d:",i); for(int j=vex[i];j!=0;j=edge[j].next){ printf("(%d,%d)->",edge[j].to,edge[j].q); } cout<<"\n"; } //邻接表遍历结束 return 0; }
1、队列的定义 queue<关键词> 队名; 2、队列的基本操作 队名.操作函数名() 队名.push(入队元素) //入队 队名.pop() //出队 队名.front() //返回值为队头 队名.back() //返回队尾 队名.size() //返回值为队中元素个数 队名.empty() //队空返回 true 不空返回false !队名.empty() //队空返回 false 不空返回 true
void bfs( int x, int y ){ //传入搜索的地点 //1.标记起点 //2.起点入队 //3.队列不空则循环: //3.1 获取队头到tmp //3.2 出队 //3.3 循环枚举tmp的4个方向: //3.3.1 判断将要走的点合法 //3.3.1.1 将合法的点入队 //3.3.1.2 将合法的点标记 }
拓扑排序
//1. 入度为0的点入栈 //2. 栈不空循环: //2.0 获取栈顶 到tmp //2.1 tmp入队 //2.2 出栈 //2.3 枚举tmp为起点的所有边: //2.3.1 将枚举到的边的终点的入度减一 //2.3.2 如果入度为0: //2.3.2.1 该终点入栈 //3.判断队列元素个数为顶点数: //遍历队列里面的元素 //否则: //输出有环
#include using namespace std; int main(){ int a[1001],n,dp[1001]={0}; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } if(n<3) { cout<<0; return 0; } for(int i=3;i<=n;i++){ dp[i]=min(a[i]+dp[i-1],min(a[i-1]+dp[i-2],a[i-2],dp[i-3])); } cout<<dp[n]; return 0; }
-
最近活动
- 蓝桥杯省赛练习第03周 作业
- 蓝桥杯省赛练习第02周 作业
- 蓝桥杯省赛练习第01周 作业
- 【CQMC】重庆小码王C++月赛 - 语法组 #3 ACM/ICPC
- 冬季训练赛 IOI
- 【CQMC】重庆小码王C++月赛 - 语法组 #1 IOI
- 秋季训练赛2 IOI
- 金牌集训营编程测试-2-20230720 IOI
- 金牌集训营编程测试-2-20230716 IOI
- 暑期集训入营算法编程题目 IOI
- 暑期集训入营语法编程题目 IOI
- 暑期集训入营笔试题目 OI
- 蓝桥杯真题练习 IOI
- 电子学会考核一级模拟题-3 IOI
- 电子学会考核一级模拟题-2 IOI
- 电子学会考核一级模拟题-1 IOI
- 等级考试一级练习 作业