自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(43)
  • 收藏
  • 关注

原创 stl学习

#include <iostream> #include <string> #include <queue> using namespace std; int main(){ queue<string>q; q.push("123"); q.push("456"); q.push("789"); cout<<q.size()<<endl; cout<<q.front()

2022-07-15 15:18:31 200

原创 conda基本操作

conda管理 Conda管理包 # 安装命令 conda install package_name # 安装numpy,输入 conda install numpy # 安装 matplotlib conda install matplotlib # 查看已安装的包 conda list # 搜索安装包 conda search search_term # 同时安装多个包 conda install numpy scipy pandas # 安装指定版本的包 conda install numpy=1.1

2022-03-01 20:42:37 1046

原创 一只小蜜蜂...

Problem Description 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。 其中,蜂房的结构如下所示。 Input 输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0<a<b<50)。 Output 对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。 Sample Input 2 1 2 3 6 Sample Output 1 3 #includ

2021-09-10 10:45:53 249 1

转载 hdu母牛的故事

Problem Description 有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛? Input 输入数据由多个测试实例组成,每个测试实例占一行,包括一个整数n(0<n<55),n的含义如题目中描述。 n=0表示输入数据的结束,不做处理。 Output 对于每个测试实例,输出在第n年的时候母牛的数量。 每个输出占一行。 Sample Input 2 4 5 0 Sample Output 2 4 6 在第5年

2021-09-10 10:11:05 233

转载 c++文件组织

2021-07-18 11:41:45 239

原创 c++之重载函数和函数模板

#include<iostream> using namespace std; int max_(int a,int b){ return (a>b?a:b); } double max_(double a,double b){ return (a>b?a:b); } long max_(long a,long b){ return (a>b?a:b); } int main(){ int a=1,b=0; cout<<max_(a,b); d

2021-07-16 20:52:28 113

原创 关于函数传参的再理解(含引用)

情景引入—小小日记 6/1的我开开心心的度过儿童节,复习一哈数据结构课上的内容。 but!,这红红的一条让我心慌。 下面是当时的源码(二叉排序树) #include <iostream> using namespace std; typedef int datatype; struct Node{ datatype data =0; Node *lchild = NULL, *rchild = NULL; }; void Insert(Node *root,datatyp

2021-06-02 22:32:16 460 1

原创 如何理解最小生成树

#include <iostream> using namespace std; #define MaxSise 10 #define positive_infinity 1000 int visited[MaxSise]={0}; typedef char datatype; typedef struct { datatype vertex[MaxSise]; int edge[MaxSise][MaxSise]; int vertexnum,edgenum; }MGr

2021-05-20 20:57:41 169

原创 并查集

#include <iostream> using namespace std; const int M=1000; int n,m,p[M]; int find(int x){ int r=x; while(p[r]!=r){//寻找根节点 r=p[r]; } int i=x,t; while(i!=r){//路径压缩 t=p[i]; p[i]=r; i=t; } return r; } void

2021-05-13 20:22:28 123

原创 洛谷P1238 走迷宫

#include <iostream> #include <vector> using namespace std; int m,n,a[15][15],book[15][15],startx,starty,dx,dy,flag=1; vector<pair<int ,int > >v; void dfs(int x,int y){ int tx=0,ty=0,k; int next[4][2]={{0,-1},{-1,0},{0,1},{1,

2021-05-11 07:52:31 219

原创 洛谷P2241 统计方形

此题需要公式如下: 矩形=正方形+长方形 #include <iostream> using namespace std; int main(){ int n,m,retangle=0,square=0,i,j; cin>>n>>m; retangle=n*(n+1)*m*(m+1)/4;//计算矩形个数 i=min(n,m);j=max(n,m); while(i){//计算正方形个数 square+=(i-

2021-05-08 14:27:28 183

原创 P3613 【深基15.例2】寄包柜

#include <iostream> #include <cstdio> #include <map> using namespace std; map<int ,map<int ,int > >data; int main(){ int n,m,q,x,y,k,z; cin>>n>>q; for(int i=1;i<=q;i++){ scanf("%d%d%d",&

2021-04-28 20:27:23 168

原创 stl map

map集合以键与值组合为元素,每个元素拥有一个键和一个值,集合以键作为排序标准。集合中各元素的键是唯一的,不重复。map可以看做是一种能使用任意下表的关联式容器。 eg:从字符串中删除字符串 #include <iostream> #include <map> #include <string> using namespace std; void print(map<string,int>t){ map<string,int>::iter

2021-04-28 20:14:45 148

原创 不区分大小写的字符串查找

#include <iostream> #include <string> using namespace std; int main(){ int count=0; string str1,str2; cin>>str1; getchar(); getline(cin,str2); //大写转小写 for(int i=0;i<str1.size();i++){ if((str1[i]>=

2021-04-22 20:44:18 1622 3

原创 洛谷P4715 【深基16.例1】淘汰赛

使用队列 #include <iostream> #include<queue> using namespace std; int main(){ int n,l,x; cin>>n; l=1<<n; queue<pair< int ,int > >q; for(int i=1;i<=l;i++){ cin>>x; q.push(make_pa

2021-04-20 21:11:42 219 2

原创 顺序表的实现

#include<cstdio> #include <cstdlib> #define max_size 10 typedef int datatype; typedef struct { datatype data[max_size]; int length; }seqlist; int Creatlist(seqlist *L,const datatype a[],int n){ if(n>max_size){ printf("n

2021-04-18 18:16:29 120

原创 关于递归

计算n的阶乘 #include <iostream> using namespace std; int factorial(int n){ if(n==1)return 1; else return n*factorial(n-1); } int main(){ cout<<factorial(5); return 0; }

2021-04-02 20:10:06 147

原创 lower_bound的使用

#include<iostream> #include<algorithm> using namespace std; int main(){ int a[5]={1,2,3,4,5}; int b[5]={1,3,4,5,2}; int *pos; pos=lower_bound(a,a+5,2);//lower_bound取的是第一个不小于‘2’(指定值)的元素的地址 int idx=distance(a,pos);//用dist

2021-04-01 13:08:16 187

原创 二分搜索

#include<iostream> using namespace std; int search(int a[],int n,int key); int main(){ int n,key; cin>>n>>key; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } cout<<search(a,n,key); return

2021-04-01 10:00:03 114

原创 vector

#include <iostream> #include <vector> using namespace std; int main(){ vector<int>v; v.push_back(444); v.push_back(666); v.push_back(233); v.pop_back();//删除最后一个元素(233) v[1]=777; for(size_t i=0;i<v.size();i

2021-03-26 09:15:05 159

原创 关于引用

#include <iostream> #include <string> using namespace std; void swap(int &c,int &d){//使用引用可以,修改实参 int t=c; c=d; d=t; } int count_number(const string &s){//不使用const,引用会默认修改实参,并且当传入const的实参的时候会报错 int count =0; for(

2021-03-25 20:02:55 127

原创 最小字典序(贪心算法)O(n)

输入一个长度为n的字符串,找到其最小字典序。 此题使用贪心算法,比较字符串两端的大小,取小的字符接入(或输出)新的字符串 。若两端相同,则比较内侧两个字符的大小,先取小的一边。可以设置标记符a,b 直到a>=b时循环结束。 #include <iostream> using namespace std; int main(){ int n; cin>>n; char str[n]; cin>>str; int a=0,b=n-

2021-03-24 20:32:29 1118

原创 c++头文件

1.cmath//数学函数,有sqrt(开方)等函数 2.

2021-03-23 20:17:36 627

原创 简述迭代器

.end()所指的位置是最后一个元素的下一个元素

2021-03-22 19:52:23 149

原创 c++中new与delete

#include <iostream> using namespace std; int main() { //堆内存 //申请:new //释放:delate //new的使用 类型 *指针变量=new 类型 // 或 类型 *指针变量=new 类型(初始值) //delete 堆内存的首地址 int *ptr =new int (233); cout<<ptr<<endl; cout

2021-03-22 18:47:55 96

原创 c++中string类的使用(持续更新)

1.将整形转为string类型 #include <iostream> #include <string> using namespace std; int main() { int a=12; string b; b=to_string(a)+"is a string"; cout<<b; return 0; }

2021-03-20 19:53:50 315

原创 c++中逆序reverse和sort的使用

reverse可以进行逆序 sort可以进行升序排列 #include<cstdio> #include<bits/stdc++.h> using namespace std; int main () { string key; cin>>key; reverse(key.begin(),key.end()); //翻转的是起点和终点这段区间 和sort用法类似;[st,ed) cout<<key<&lt

2021-03-16 17:13:11 6577

原创 关于c++的动态申请(持续更新)

#include<iostream> using namespace std; int main(){ int *a,*b; char *c; a=new int;//分配一个整形空间,若成功则a指向该空间,否则a为null b=new int(10);//分配一个整形空间且给这个整形空间附上初值10 c=new char[10];//分配一个字符数组(字符串)空间,即c为字符串指针 delete a;//释放a所指的整形空间 delete []c;//释放c所指向的字符串空间

2021-03-15 20:37:23 506

原创 凯撒密码

凯撒密码。它是一种替换加密的技术,明文中的所有字母都在字母表上向后(或向前)按照一个固定数目进行偏移后被替换成密文。 如下偏移4位,a->e。 #include<iostream> using namespace std; int main() { char c; while ((c = getchar()) != '\n') {//键入回车就结束输入,空格只起间隔作用 if ((c >= 'a' && c <= 'z') || (c >= 'A'

2021-02-22 11:09:48 254

原创 素数,质数筛

判断m是否质数:只需m能被判断2到sqrt(m)之间的数整除即可 下面输出100-200之间的素数 #include<iostream> #include<cmath> #include<iomanip> using namespace std; int main() { int m, i,k,n=0; bool prime; for ( m = 101; m <=200; m += 2) { prime = true; k = int (sqrt(m

2021-02-22 11:00:52 138

原创 c++控制输入输出及cctype使用

1.赋值操作 #include<iostream> using namespace std; int main() { int a, b, c, d; a = 1; d = c = b = a;//赋值表达式 cout << a << b << c << d; return 0; } 相当于a赋给b,b赋给c,最后c赋给d。 2.标准输入输出的控制符 #include<iostream> #include<ioman

2021-02-21 19:47:44 186

原创 选择排序

1.和插入排序法和冒泡排序一样,选择排序也将数组分为已排序和未排序两部分。 主要步骤: 重复n-1次下述操作 1.找出未排序部分的最小值minj; 2.将minj位置的元素和未排序的起始元素交换 主要变量: i:循环变量,表示未排序的起始元素,从数组开头向末尾移动。 minj:各轮循环处理中,第i号到第n-1号的最小值的位置 j:循环变量,用来查找未排序部分中最小值的位置(minj) #include<stdio.h> /*Ñ¡ÔñÅÅÐò£¨0Æðµã£©*/ int selectionso

2021-02-18 17:17:05 99

原创 冒泡排序

1.和插入排序法一样,冒泡排序也将数组分为已排序和未排序两部分。 主要步骤:从数组的末尾依次比较相邻的两个元素,如果大小关系相反交换位置。 主要变量: 数组:a【n】 i:循环变量,表示未排序部分的开头元素 j:循环变量,用于对未排序部分的相邻两元素比较,从a的末尾n-1开始,减小到i+1结束 eg: #include<iostream> using namespace std; //使用flag的冒泡排序 int bubblesort(int a[],int n){ int sw=0;

2021-02-18 11:08:58 92

原创 排序方法

(一)插入排序法 1将开头元素视作已排序 2执行下述处理,知道未排序部分消失 取出未排序的部分的开头元素赋给变量v 在已排序部分,将所有比v大的元素向后移动一格单位 将已取出的元素v插入空位 插入排序的复杂度:O(n^2) eg: 在这里插入图片描述 `#include<stdio.h> #include //按顺序输出数组元素 void trace(int a[], int n) { int i; for (i = 0; i < n; i++) { if (i > 0) { pr

2021-02-17 23:43:39 184

原创 dfs深度优先搜索

深度优先搜索: 它从某个状态开始,不断地转移状态直到无法转移,然后退回到前一步的状态,如此不断重复知道找最终的解。所以递归函数实现比较容易。 如下例: 部分和问题: 从a1开始按顺序决定每个数加还是不加,在全部n个数都决定后判断它们的和是不是k即可 。 因为状态数是2(n+1),所以复杂度是O2n。 //输入; int a[max_n]; int n,k; //已经前i项得到了和sum,然后对于i项之后进行分支 bool dfs(int i,int sum){ //如果前i项都计算过了,则返回sum是否

2021-02-08 19:30:20 148 1

原创 队列的初步认识

队列与栈 相同 的是也有push和pop的操作。 但是与栈不同的是pop取出的是最低端元素 ,也就是(先进先出)。 使用例: #include<queue> #include<cstdio> using namespace std; int main(){ queue<int>que;//声明储存int类型数据的队列 que.push(1);//{}->{1} que.push(2);//{1}->{1,2} que.push(3);//{1,2}-&

2021-02-08 18:02:48 187

原创 对栈的初步了解

栈(stack)是支持push和pop两种操作的数据结构。 push是在栈的顶端放入一组数据的操作。 而pop是在栈的顶端取出一组数据的操作。 总之就是 后进先出 在c++的标准库中stack::pop完成的仅是移除最顶端的数据。 如果要访问最顶端的数据则需要stack::top 函数调用的过程是通过栈实现的。 使用stack的例子如下: #include<stack> #include<cstdio> using namespace std; int main() { s

2021-02-01 19:24:31 126

原创 最基础的穷竭搜索(1)

**递归函数** {1.调用自身 2.递归的终止条件 } 关于斐波那契数列的函数 A0=0,A1=1 An=A(n-1)+A(n-2) (n>1) int fib(int n){ if(n<=1) return n; return fib(n-1)+fib(n-2); } 如果fiber(n)的n是一定的,无论调用多少次都会得到相同的结果,为此可以用数列把结果存起来。 int memo[max_n + 1]; int fib(int n) { if (n <= 1) ret

2021-02-01 19:06:16 129

原创 抽签问题与二分搜索

四重循环的复杂度为O(n4)若1<=n<=1000则为n12,不能满足要求。 #include<cstdio> const int max_n = 50; int main() { int n, m, k [max_n]; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", k[i]); } bool f = false; //通过四重循环枚举所有方案 fo.

2021-02-01 18:44:57 178

原创 多组输入问题

例: KiKi学习了循环,BoBo老师给他出了一系列打印图案的练习,该任务是打印用“*”组成的线段图案。 输入描述: 多组输入,一个整数(1~100),表示线段长度,即“*”的数量。 输出描述: 针对每行输入,输出占一行,用“*”组成的对应长度的线段。 #include<iostream> using namespace std; int main(){ int n; while(cin>>n){//解决多组输入 for(int i=0;i<n;

2021-01-19 23:30:15 389

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除