自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(49)
  • 问答 (4)
  • 收藏
  • 关注

原创 我的学习笔记

打开摄像头捕获cv2.imshow('trackbar',img)必须在窗口中显示

2022-07-01 20:01:33 937 1

原创 双指针方法

class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) {//感觉双指针会与滑动窗口联系起来//这道题感觉像滑动窗口 还感觉有点像二分法//先排序//建立一个存结果的数组 vector<vector<int>> result; sort(nums.begin(), nums.end()); for(int...

2022-04-28 16:23:50 354

原创 哈希表相关题目c++

哈希表特点是对应有索引,通过一个哈希函数对应出一个下标来存储.class Solution {public: bool isAnagram(string s, string t) { int num[27]={0}; for(int i=0;i<s.size();i++)//哈希表 { num[s[i]-'a']++; } for(int j=0;j<t.size();j++)//一个

2022-04-25 21:12:00 964

原创 链表的相关题目

自己定义一个链表结点结构体// 单链表struct ListNode { int val; // 节点上存储的元素 ListNode *next; // 指向下一个节点的指针 ListNode(int x) : val(x), next(NULL) {} // 节点的构造函数 给val的赋值为x,next的下一个结点指向了空};获取第index点的值,我之前的想法是定义一个k。让k++,直到k=index,有一个更简便的方法让index--,让指针移动。 /

2022-04-21 17:20:19 1048

原创 JAVA图形用户界面开发

package Cai;import javax.swing.*;import java.awt.*;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;public class Student {//组件 JTextField name;//写名字的文本框 JTextField ID; JTextField number; JTextField result; JB.

2022-04-19 23:16:32 478

原创 Java作业

HashSetpackage Cai;import java.util.Random;import java.util.Scanner;import java.util.HashSet;public class Main { public static void main(String[] args) { Scanner input=new Scanner(System.in); Random rdm=new Random(); Has

2022-04-09 17:40:24 947

原创 长度最小的子数组

第一种:最能想到的就是两个for循环,i为起始点,j依次遍历i后面的数,符合条件跳出内层循环,i移动一个又重复上面的步骤 。但这样效率有点低。第二种(从代码随想录那里学习到的):滑动窗口,j是终止位置,遍历整个数组,动态改变i起始的位置。当每次由i和j组成的窗口大了的时候即该窗口的和大于目标值,就需要缩小窗口,即移动i的值让i++,但要sum减掉之前nums[i]的值class Solution {public: int minSubArrayLen(int target, vect..

2022-04-08 17:28:38 484 1

原创 Meteor Shower S(bfs)

#include<iostream>#include<queue>using namespace std;int map[305][305];//初始化陨石地图 int v[305][305];//标记该点是否已经走过lint ans[305][305];//存储最短时间的地图,二维数组的内容是到该点的最短时刻int dx[5] = { 0,0,0,1,-1 };int dy[5] = { 0,1,-1,0,0 };//方便移动和处理陨石砸落int flag = 0.

2022-04-05 10:45:49 293

原创 BFS(stl大法好)

给定一个点,要把该点的所有能访问的点都访问一遍。也需要一个访问标志数组,标记该点是否被访问过。还需要用到队列的知识,队列特点是先进先出。思想是:把1的邻接点输出且都入队,然后访问到1没有邻接点的时候,把1的邻接点出队一个(比如说是点2)并当成新的顶点,继续访问其邻接点输出并入队,2访问到没邻接点的时候,这个时候就是3出队并输出重复上面的步骤,直到所有的点被输出。循环的一个终止条件是队列为空了。#include<iostream>#include<algorithm>#d

2022-04-02 18:38:12 374

原创 从n个数中选k个数(组合问题)

不降原则:选出的数全部保证是升序,这样就可以避免选重。eg:1 2 3 4 5我们可以选:1 2 31 2 41 2 5然后把第二位的2加1变成3,因为是升序1 3 41 3 5再把3加1变成41 4 5到这里以1开头的的组合就全部枚举完了,接下来就以2开头,因为时刻要满足是升序2 3 42 3 52 4 53 4 5这里就把这5个数全部枚举完了。这道题重点就是选数然后判断结果是否为质数选数的过程就用了不降原则,利用递归实现#incl

2022-04-02 13:32:52 3177

原创 八皇后问题

#include<iostream>#include<algorithm>using namespace std;int a[20]={0};//a[i]的值等于第i行第几列放了一个皇后int n;//几维度int k=0;//记录有几种解法bool check(int x,int y)//第x行能不能放在第y列{ for (int i = 1; i <= x; i++)//遍历前x行 判断放入是否有冲突 { if (a[i] == y||x+y==i+.

2022-03-31 20:19:08 397

原创 熟悉继承(java)

package Cai;import java.util.Scanner;class Person{//子类的使用 private String name; private char sex; private String id; private String phone; private String email; public Person() { name="wang"; sex='女'; .

2022-03-30 19:33:01 469

原创 DFS(不成熟版)

要有一个数组来存该点是否被标记,如果该点被访问了要标记,直到访问完了所有的点。用递归,递归传入的就是访问到的新一个点,要对它进行标记访问过了,再去遍历该点的邻接结点,看能不能进行访问。...

2022-03-30 11:58:06 224

原创 无聊的逗(二进制法)

c++版#include<iostream>#include<algorithm>#include<cmath> using namespace std;int main(){ int n;//n个木棍 每根的长度 cin>>n; int length[20]={0};//存每个木棍的长度 int number[1<<n]={0};//存储每一种组合方式的总长度 难道是因为没有初始化的原因?? 数组初始化很重要 fo

2022-03-25 19:36:43 1543

原创 按位运算(知识)

按位与(&)0&0=0 0&1=0 1&1=1 只有两个都是1才输出1,其余输出0eg:int a=3,b=5转换成二进制3=0000 00115=0000 0101 对应位看结果3&5=0000 0001所以int c=a&b=0000 0001=1按位或(|)0&1=1 0&0=0 1&1=1 只要有一个1就为1还是3和53=0000 00115=0000 0101 对应位看结果3|5=00.

2022-03-24 20:54:47 296

原创 数字游戏蓝桥杯算法训练

#include<iostream>#include<algorithm>using namespace std;int main()//思想就是把1234的所有排列列出来,符合相邻相加等于sum的就输出 { int n,sum; cin>>n>>sum; int A[100]={0}; int B[100]={0}; for(int i=0;i<n;i++) { A[i]=i+1; } /*while(next_per.

2022-03-24 18:31:13 4243

原创 合并石子(动态规划)

问题描述: 在一条直线上有n堆石子,每堆有一定的数量,每次可以将两堆相邻的石子合并,合并后放在两堆的中间位置,合并的费用为两堆石子的总数。求把所有石子合并成一堆的最小花费。输入格式:输入第一行包含一个整数n,表示石子的堆数。  接下来一行,包含n个整数,按顺序给出每堆石子的大小 。输出格式:输出一个整数,表示合并的最小花费。测试用例:51 2 3 4 5输出34分析:第一堆和第二堆合并需要花费的钱是1+2=3,第一堆和第二堆合并后的总的再和第三堆合并即花费3+3=6,花费

2022-03-13 19:51:31 4382 1

原创 蓝桥杯 最大的最小公倍数

输入一个数n,在1~n中任意找3个数求出最大公倍数。思路:任意相邻的两个数互质,相邻的几个数相乘最大,讨论n的情况,n为偶数(偶数里又分n是否是3的倍数,因为取得是3个数)和奇数。#include <iostream>#include <cmath>using namespace std;int main(){long long A=0;long long n;cin>>n; if(n%2!=0) { A=n*(

2022-03-11 10:10:58 210

原创 动态规划 印章蓝桥杯 c++

每一步的变化会导致其他变量的变化,多个变量在变,但每一步的变化之间是有联系的一:有重复的:就表明前面买的 i-1 张,已经凑齐了 j 种。dp[i] [j] = dp[i-1] [j] * ( j / n ); j/n是什么意思?因为dp[i] [j]已经确定了买的第i张是重复的,所以这第i张是从前j中的任意一张都可以,要乘上概率j/n。#include<iostream>#include<algorithm>#include<cmath>using n

2022-03-06 19:38:33 377

原创 背包问题(c++)

#include<iostream>#include<algorithm>using namespace std;int f[5][9] = { 0 };int w[5] = { 0,2,3,4,5 };//物品重量int v[5] = { 0,3,4,5,8 };//物品价值int main() { //v=f(i,w)函数关系 i是能选的前几件物品 w是背包容量 v是总价值 for (int i = 1; i < 5; i++)//物品序号 { ...

2022-03-05 16:29:08 1498

原创 斐波那契数列(递归和非递归)

递归int f(int n)// 1 1 2 3 5 8{ if (n <= 2) return 1; else return f(n - 1) + f(n - 2);}非递归int f(int n)// 1 1 2 3 5 8{ int a = 1;//第一位 int b = 1;//第二位 int c = a;//第三位 while (n > 2) { c = a + b;//因为每次都是前两项相加的和等于后一项 a = b; b =

2022-03-05 14:10:56 172

原创 特殊的回文数(c++)

#include<iostream>using namespace std;int main() { int n; cin >> n; for (int i = 10000; i <= 999999; i++) { int temp = 0; int number = i; int k = 0; while (number > 0) { k += number % 10;//每一位上求和 temp *= 10; tem..

2022-03-05 11:12:15 303

原创 C++中的小知识点

小写字母a的ASCII码值是97,大写A是65。 ASCII码值转成字符在前面加char强制转换,eg:char(97)。 字母转换成大小写,利用ASCII码,因为相差32,转成大写减32,转成小写加32。 j=j/10,取一个数中的每一位,循环一直进行的条件是j>0,当j取到最后一位的时候,j/10就等于0了。 整数转成字符串,加'0',eg:5+'0',字符串数字转成整型数字,减'0',eg:5-'0'。 对于不确定的输入数据 可以用:char name[20]; //get将一行读入数

2022-03-04 16:33:28 561

原创 一串单词找字母出现次数最多的(c++)

#include<iostream>#include<cstdio>#include <iomanip>#include<cmath>#include<string>#include<algorithm>#include<cctype>using namespace std;int main(){ string A; cin >> A; char a[27];//存放26个字母 字母顺序.

2022-03-01 20:08:25 1658

原创 简单的找零过程(JAVA)

package Cai;import java.util.Scanner;public class test { public static void main(String[] args) { int a=0;//应收 int b=0;//实收 Scanner input=new Scanner(System.in); a=input.nextInt(); b=input.nextInt(); .

2022-02-28 20:59:58 912

原创 P4924 [1007]魔法少女小Scarlet (C++)

#include<iostream>#include<cstdio>#include <iomanip>#include<cmath>#include<string>#include<algorithm>using namespace std;int A[1000][1000] = {0};//用来存放生成的矩阵int temp[1000][1000] = { 0 };//临时数组struct rule { i.

2022-02-14 15:46:06 461

原创 美赛latex模板

%%%% This is file `mcmthesis-demo.tex',%% generated with the docstrip utility.%%%% The original source files were:%%%% mcmthesis.dtx (with options: `demo')%% %% -----------------------------------%% %% This is a generated file.%% %% Copyright.

2022-02-13 22:29:15 748

原创 texworks editor打不开时怎么办

2022-02-12 22:52:20 1310

原创 P1563玩具谜题(C++)

#include<iostream>#include<cstdio>#include <iomanip>#include<cmath>#include<string>#include<algorithm>using namespace std;//有点像循环队列,关键是移动的时候不能简单加减,要使用模运算来移动struct student { int flag;//朝内还是朝外 char name[20];}.

2022-02-09 12:07:41 475

原创 P2670 扫雷游戏(c++)

#include<iostream>#include<cstdio>#include <iomanip>#include<cmath>#include<string>#include<algorithm>using namespace std;char a[101][101];//地图int s[101][101] = { 0 };//输出答案int dx[8] = { -1,-1,-1,0,+1,+1,+1,0 .

2022-02-06 20:05:10 2264

原创 P1598垂直柱状图

#include<iostream>#include<cstdio>#include <iomanip>#include<cmath>#include<string>using namespace std;int main(){ string a,b,c,d; getline(cin, a); getline(cin, b); getline(cin, c); getline(cin, d); int A[30] .

2022-01-12 19:33:19 333

原创 P1308 统计单词数

#include<iostream>#include<cstdio>#include <iomanip>#include<cmath>#include<string>using namespace std;int main(){ string word, sentence; getline(cin, word); getline(cin, sentence); int w = word.size(); int s = s.

2022-01-11 17:50:55 216

原创 P1319 压缩技术

#include<iostream>#include<cstdio>#include <iomanip>using namespace std;int main(){ int n; cin >> n;//几乘几的矩阵 int count = 1;//记录是0还是1 int s = 0; int t = 0;//判断输出回车 while (s < n*n) { int b;//要输入的数 cin >> b.

2022-01-08 18:21:45 335

原创 杨辉三角(C++)

#include<iostream>#include<cstdio>#include <iomanip>using namespace std;int b[900][900]= {0};int main(){ int n; cin >> n; b[0][0] = 1; for (int i = 1; i < n; i++)// 控制输出n行 { for (int j = 1; j < i; j++)//控制一行输.

2022-01-08 10:51:17 704

原创 P5731 蛇形方阵

#include<iostream>#include<cstdio>#include <iomanip>using namespace std;int b[900][900]= {0};int main(){ int n; cin >> n;//一直往一个方向填数,填不动了就转向 int i = 0, j = 0;//行数列数 for (int k = 1; k <= n * n;) {//向右转 while (j &.

2022-01-07 20:19:48 394

原创 P2615 神奇的幻方

#include<iostream>#include<cstdio>using namespace std;long s[10001][10001] = {0};int n;int i, j;//i表示层,j表示列,sum计数 int main(){ cin >> n; i = 1, j = n / 2 + 1;//因为1是从n/2+1列开始,所以以此为j //规律是sum为n的倍数时就向下走一个,其余都向右上走 int k = 1; .

2022-01-07 13:58:13 141

原创 PTA1027打印沙漏

#include<iostream>using namespace std;int main()//打印沙漏 打多少空格或者星号要找规律 一般联系它所在的行数或者列数{ int k; cin >> k; char symbol; cin >> symbol; int n = 1; //int i = 0; 下面用到的i都应该定义成局部变量而不是全局变量 while (2 * n*n - 1 <= k)//计算层数 { n++; } n.

2021-12-31 17:30:48 284

原创 直接插入排序 简单选择排序 冒泡排序 快速排序(C++)

#include<iostream>#include <stdlib.h>#include<time.h>//生成随机数需要用到的一个头文件using namespace std;#define MAXSIZE 100typedef int ElemType;typedef struct { ElemType elem[MAXSIZE + 1]; //数据元素存储空间基址, 0 号单元留空 int length; //表长度}SqList;//创建排.

2021-12-14 21:08:08 1479

原创 折半查找(c++)

#include<iostream>#include <stdlib.h>using namespace std;#define SPACE 100//顺序查找表的定义typedef int ElemType;typedef struct { ElemType *elem; //数据元素存储空间基址,0 号单元留空 int length; //表长度}SSTable;//创建查找表void CreateTable(SSTable &ST) { //根.

2021-12-08 21:05:23 1932

原创 图的基本操作,深度优先遍历图,广度优先遍历图(C++)

#include<iostream>#include <stdlib.h>using namespace std;#define INFINITY 32767 //最大值 无穷#define MAX_VERTEX_NUM 20 //最大顶点个数typedef int QElemType;#define MAXQSIZE 100typedef char VertexType; //图的顶点的类型typedef enum { DG, DN, UDG, UDN }Gr.

2021-12-05 15:48:08 1245

空空如也

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

TA关注的人

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