![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++编程
文章平均质量分 71
臧初之
有时候,总想记录点什么东西
展开
-
[OJ]分数个数问题--采用欧拉公式
1/6,1/5,1/4,1/3,2/5,1/2,3/5,2/3,3/4,4/5,5/6可以看到这个集合中包含的分数有11个。例如N=5时,(1,2) , (1,3), (1,4), (1,5), (2,3), (2,5), (3,4), (3,5), (4,5)共9对数是互质数。2.这里1/6,1/5,1/4,1/3,2/5,1/2,3/5,2/3,3/4,4/5,5/6都是互为质数,可以根据欧拉公式求解。直接利用公式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)……...原创 2022-08-15 09:09:23 · 19384 阅读 · 2 评论 -
[OJ]信仰之跃、互质、求解同余方程、新世纪线段覆盖
现给定一根坐标轴,坐标轴上有n条线段,每条线段从1开始编号,若线段编号为k,则该线段覆盖的区间是:[(k-1)×m,(k-1)×m+l]。因此,只需要判断(8,11)(19,22)之间的数是否是d的倍数(注意,这里是开区间),仅且判断一次,如果是,这直接跳出循环,返回数字。则用(n-1)*m+l来对d取余,设j=((n-1)*m+l)%d,那么还差d-j个数便是下一个d的倍数。当k=1时,[(k-1)*m,(k-1)*m+l]为[0,8];当超出n的时候,例如n=2,d=4,m=11,l=8;...原创 2022-08-15 09:06:58 · 19290 阅读 · 1 评论 -
[C++]error MSB6006: “cmd.exe”已退出,代码为 123。
问题:error MSB6006: “cmd.exe”已退出,代码为 123。解决办法:打开.vcxproj文件。发现原来编译不报错testTranslateQtUi.ui的配置如下:<CustomBuild Include="testTranslateQtUi.ui"> <FileType>Document</FileType> <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"&g原创 2021-10-08 09:11:21 · 2603 阅读 · 0 评论 -
[C++]在VS2017中,添加Qt的ui文件,编译运行opencv+qt5程序的过程
在基于C++的opencv编程过程中,为了满足以后的跨平台需求,同时为了简单高效,选择Qt作为界面。1.下载opencv,并且配置opencv到VS2017中2.Qt5以及VS2017对应的Qt插件的安装:注意:最好是按照qt5,安装qt6运行程序会报几百个错误使用VS2017编写QT GUI程序在VS2017中下载插件时,速度感人,最好是先把Qt插件下载下来(下载后为.VSIX文件),在进行安装,参考下面博客:Visual Studio2019安装vsix扩展文件3.添加项目选择解决方案=原创 2021-09-25 12:00:09 · 4611 阅读 · 4 评论 -
[C++]A和B是两个字符串,用最少的字符操作将A转换为B,操作包括:删除1个字符、插入1个字符、替换1个字符。(使用动态规划)
关于题目的具体介绍:A和B是两个字符串,用最少的字符操作将A转换为B,操作包括:删除1个字符、插入1个字符、替换1个字符。可参考:【动态规划】最小编辑距离(字符串A到字符串B变化最少要多少步)】https://blog.csdn.net/ma2413419/article/details/82693319/?utm_medium=distribute.pc_relevant.none-task-blog-title-2&spm=1001.2101.3001.4242其相关C++编程,转载 2020-12-08 20:59:46 · 3802 阅读 · 1 评论 -
[C++]内存变化图解---深拷贝与浅拷贝的区别
每次学完深拷贝与浅拷贝,过一段时间总会忘记,原创 2020-11-21 16:05:05 · 384 阅读 · 0 评论 -
[C++]strassen算法-现实奇数
当n为奇数时,先给矩阵加一行一列0,使之成为一个偶数矩阵,再调用Strassen偶数实现算法中的Multi_Even()方法,计算偶数矩阵相乘。#include<iostream>using namespace std;class Matrix{public: int **m; int n; Matrix(){ m = NULL; n = 0; } Matrix(int n){ this->n = n; m = new int*[n]; for (i原创 2020-11-14 17:56:42 · 808 阅读 · 1 评论 -
[C++]strassen算法-现实偶数(不包含2的幂次)
Strassen要求阶n是2的幂,但这样的情况很少。#include<iostream>using namespace std;class Matrix{public: int **m; int n; Matrix(){ m = NULL; n = 0; } Matrix(int n){ this->n = n; m = new int*[n]; for (int i = 0; i < n; i++){ m[i] = new int[n]转载 2020-11-14 16:59:42 · 1023 阅读 · 0 评论 -
[C++]矩阵乘法Strassen算法-----代码实现
关于矩阵乘法的Strassen算法,这里不再叙述,推荐简书博客:https://www.jianshu.com/p/6e21f8e872fd本篇博客便是参考该简书的算法思想,采用C++进行代码实现,可作为上述简书的补充。关于使用参数传递二维数组,可参考:https://www.cnblogs.com/huipengly/p/8892110.html#include<iostream>using namespace std;/*可以传递二维数组作为参数,有两种方法,1.chang原创 2020-11-12 23:11:17 · 3065 阅读 · 0 评论 -
[C++]练习:使用模版进行插入排序
对上一篇博客进行拆分、修改#include "iostream"using namespace std;//使用插入排序进行内部排序,测试template<class T>void test(T arr[], int Length){ //先写出插入排序算法,再将其改为希尔排序,将所有1的地方改为gap for (int i = 1; i < Length; i++) { T val = arr[i];//记录值 int j = i;//记录下标 while原创 2020-10-25 20:30:47 · 131 阅读 · 0 评论 -
[C++]练习:使用模版进行快速排序,并改进(递归、非递归、近乎有序时、三个数取中值)
对上一篇博客进行拆分,修改#include "iostream"#include<stack>using namespace std;//快速排序template <class T>int QuickSort(T arr[], int begin, int end){ if (begin < end){ T temp = arr[begin]; //int i = begin; //int j = end; while (begin <原创 2020-10-25 20:23:29 · 147 阅读 · 0 评论 -
[C++]练习:使用模版进行希尔排序(2种方法(内部为冒泡排序、插入排序))
上一篇博客写得有点乱,将其改改#include "iostream"using namespace std;//内部使用冒泡排序,进行希尔排序template<class T>void ShellBubbleSort(T a[], int Length){ for (int gap = Length / 2; gap > 0; gap /= 2){ for (int i = 0; i < Length - 1; i += gap){ for (int j =原创 2020-10-25 20:14:54 · 94 阅读 · 0 评论 -
[C++]练习:使用模版进行冒泡排序
#include "iostream"using namespace std;//冒泡排序,外层遍历n-1次,内层每次对n-i-1个数进行比较 template<class T> void BubbleSort(T arr[],int Length){ for (int i = 0; i < Length - 1; i++) { for (int j = 0; j < Length - i - 1; j++) { if (arr[j]>arr原创 2020-10-24 12:23:16 · 107 阅读 · 0 评论 -
[C++]输入三个整数x,y,z,请把这三个数由小到大输出
#include<iostream>using namespace std;//题目:输入三个整数x,y,z,请把这三个数由小到大输出。void test04(){ int x, y, z; cout << "输入三个整数x,y,z" << endl; cin >> x >> y >> z; if (x>...原创 2020-05-05 22:22:26 · 5358 阅读 · 0 评论 -
[c++]输入三个整数x,y,z,求这三个数最小值
#include<iostream>using namespace std;//题目:输入三个整数x,y,z,求这三个数最小值。void test03(){ int x, y, z; cout << "输入三个整数x,y,z" << endl; cin >> x >> y >> z; int k = (...原创 2020-05-05 22:16:01 · 7966 阅读 · 0 评论 -
[C++]打印出所有的“水仙花数”
#include<iostream>using namespace std;void test02(){ //题目:打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数, //其各位数字立方和等于该数本身。例如:153是一个“水仙花数”, //因为153 = 1的三次方+5的三次方+3的三次方。 for (int i = 100; i < 1000; i...原创 2020-05-04 23:35:43 · 2915 阅读 · 0 评论 -
[C++]判断101-200之间有多少个素数,并输出所有素数
自己慢慢调试出来的,过程很难受,各位勿喷#include<iostream>using namespace std;//判断101-200之间有多少个素数,并输出所有素数void test01(){ bool flag;//设置一个标志变量 flag = true;//默认为素数(true) for (int i = 101; i <=200; i++) ...原创 2020-05-04 23:31:57 · 1384 阅读 · 0 评论 -
[C++]将一个正整数分解质因数,例如:输入90,打印出90=2*3*3*5
#include<iostream>using namespace std;//将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5int main(){ int n; cout << "请输入一个正整数" << endl; cin >> n; while (n != 1) { for (int i = 2; i ...原创 2020-05-03 23:13:35 · 2157 阅读 · 0 评论 -
[C++]辗转相除法——输入2个正整数m和n,求其最大公约数和最小公倍数
#include<iostream>using namespace std;//输入2个正整数m和n,求其最大公约数和最小公倍数int main(){ int m, n; cout << "请输入真正数m和n" << endl; cin >> m >> n; if (m < n) { int t; t ...原创 2020-05-03 23:11:48 · 4719 阅读 · 0 评论