
C++
文章平均质量分 65
qq_30339595
人类,诗意地栖息在大地上。
展开
-
C++ lambda表达式
lambda表达式中[]表示使用的外部变量有传值和引用两种方式[]表示不使用外部变量[&]表示全部用引用的方式[=]表示全部用值的方式[=,&x]表示x用引用,其他的变量用传值原创 2020-10-17 13:29:07 · 202 阅读 · 0 评论 -
dynamic_cast的用法
#include<ctime>#include <iostream>using namespace std;class CBasic{public: virtual int test() { cout << "Basic" << endl; return 0; } // 一定要是 virtual};class CDerived : public CBasic{public: virtual int test() { c原创 2020-10-17 13:25:09 · 338 阅读 · 0 评论 -
C++动态链接库和静态链接库
库是一些最常用的、成熟的、可复用的代码,库代码编译成目标文件后打包存放。静态 .lib/.a动态 .dll/.soSystem32动态链接库为什么需要链接库?1.底层 2.保护代码CRT C运行时库VC++提供的CRT静态运行时库libc.lib 或者libcd.lib 单线程libcmt.lib或者libcmtd.lib 多线程动态运行时库msvcrt.dll msvcr...原创 2019-11-27 14:49:52 · 316 阅读 · 0 评论 -
C++封装基础知识
对象数组A a[3] 栈A *p=new A[3] 堆全局、常量、代码delete[]p拷贝构造函数A a(const A&b)深拷贝和浅拷贝浅拷贝指针指向同一块内存 ,内存覆盖 不能重复释放this指针参数和成员重名的时候用,所在对象本身的地址const修饰成员函数,不能修改数据成员的值。实际是const修饰了this指针常量成员函数只能用初始化列表常对象调用的...原创 2019-11-26 14:40:24 · 290 阅读 · 0 评论 -
放苹果
题目描述把 M 个同样的苹果放在 N 个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?注意:5、1、1 和 1、5、1 是同一种分法,即顺序无关。输入描述:输入包含多组数据。每组数据包含两个正整数 m和n(1≤m, n≤20)。输出描述:对应每组数据,输出一个整数k,表示有k种不同的分法。示例1输入7 3输出8// write your code here cpp// pat.c...原创 2018-02-24 21:40:41 · 200 阅读 · 0 评论 -
False Coin
时间限制:1秒 空间限制:65536K 热度指数:412 算法知识视频讲解题目描述The "Gold Bar"bank received information from reliable sources that in their last group of N coins exactly one coin is false and differs in weight from other co...原创 2018-02-23 23:00:19 · 230 阅读 · 0 评论 -
Pre-Post (已知先序和后序遍历的m叉树有几种)
时间限制:1秒 空间限制:65536K 热度指数:173 算法知识视频讲解题目描述We are all familiar with pre-order, in-order and post-order traversals of binary trees. A common problem in data structure classes is to find the pre-order tra...原创 2018-03-02 14:43:41 · 2166 阅读 · 0 评论 -
PAT Radix(二分法求基数)
1010. Radix (25)时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueGiven a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is "yes", if 6 is a d...原创 2018-03-09 20:58:51 · 360 阅读 · 0 评论 -
Is It A Tree?
题目描述A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following properties. The...原创 2018-02-22 13:48:55 · 948 阅读 · 0 评论 -
Powerful Calculator(带符号的大整数的加减乘)
时间限制:1秒 空间限制:65536K 热度指数:393 算法知识视频讲解题目描述 Today, facing the rapid development of business, SJTU recognizes that more powerful calculator should be studied, developed and appeared in future market s...原创 2018-03-01 13:26:10 · 410 阅读 · 0 评论 -
路径打印
时间限制:1秒 空间限制:32768K 热度指数:470 算法知识视频讲解题目描述给你一串路径,譬如: a\b\c a\d\e b\cst d\ 你把这些路径中蕴含的目录结构给画出来,子目录直接列在父目录下面,并比父目录向右缩一格,就像这样: a b c d e b cst d 同一级的需要按字母顺序排列,不能乱。输入描述: 每个测试案例第一行为一个正整数n(n...原创 2018-03-01 10:57:23 · 1242 阅读 · 1 评论 -
日志排序
题目描述有一个网络日志,记录了网络中计算任务的执行情况,每个计算任务对应一条如下形式的日志记录: “hs_10000_p”是计算任务的名称, “2007-01-17 19:22:53,315”是计算任务开始执行的时间“年-月-日 时:分:秒,毫秒”, “253.035(s)”是计算任务消耗的时间(以秒计) hs_10000_p 2007-01-17 19:22:53,315 253.035(s) ...原创 2018-02-21 14:21:43 · 1078 阅读 · 0 评论 -
最短路径(并查集+kruskal最小生成树)
时间限制:1秒 空间限制:65536K 热度指数:1293 算法知识视频讲解题目描述N个城市,标号从0到N-1,M条道路,第K条道路(K从0开始)的长度为2^K,求编号为0的城市到其他城市的最短距离输入描述:第一行两个正整数N(2<=N<=100)M(M<=500),表示有N个城市,M条道路接下来M行两个整数,表示相连的两个城市的编号输出描述:N-1行,表示0号城市到其他城市的...原创 2018-03-03 22:23:51 · 856 阅读 · 0 评论 -
毕业bg
时间限制:1秒 空间限制:65536K 热度指数:251 算法知识视频讲解题目描述 每年毕业的季节都会有大量毕业生发起狂欢,好朋友们相约吃散伙饭,网络上称为“bg”。参加不同团体的bg会有不同的感觉,我们可以用一个非负整数为每个bg定义一个“快乐度”。现给定一个bg列表,上面列出每个bg的快乐度、持续长度、bg发起人的离校时间,请你安排一系列bg的时间使得自己可以获得最大的快乐度。 ...原创 2018-03-05 19:46:59 · 149 阅读 · 0 评论 -
cornerSubPixel亚像素角点检测源码分析(最小二乘法)
OpenCV的中有cornerSubPixel()这个API函式用来针对初始的整数角点坐标进行亚像素精度的优化,该函式原型如下:C++: void cornerSubPix(InputArray image, InputOutputArray corners, Size winSize, Size zeroZone, TermCriteria criteria);image为输入的单通...转载 2018-12-11 17:00:37 · 1705 阅读 · 0 评论 -
Eigen实现欧拉角、四元数和旋转矩阵之间的变换
include相应的头文件#include <Eigen/Geometry>旋转矩阵和旋转向量的表示和声明及旋转// 3D 旋转矩阵直接使用 Matrix3d 或 Matrix3fEigen::Matrix3d rotation_matrix = Eigen::Matrix3d::Identity();// 旋转向量使用 AngleAxis, 它底层不直接是 Matrix ...原创 2018-12-03 21:35:03 · 2718 阅读 · 0 评论 -
二维指针实例
1 #include<stdio.h> 2 int main(){ 3 char *str[]={"welcome","to","fortemedia","nanjing"}; 4 char **p=str+1; 5 str[0]=(*p++)+1; 6 str[1]=*(p+1); 7 str[2]=p[1]+3; 8 str[3]=p[0]+(str...原创 2018-12-05 21:10:32 · 631 阅读 · 0 评论 -
ubuntu 安装 google Gtest
安装gtest分三步:1.安装源代码在ubuntu的桌面上,右键选择打开终端,在终端中输入如下命令:sudo apt-get install libgtest-dev下载源码后,apt将会在目录/usr/src/生成gtest文件夹来存放源码.2. 编译源代码接着刚才的命令,我们继续再刚才打开的终端中输入: cd /usr/src/gtest来进入源码存放的地方,里面的文件...转载 2018-12-05 13:32:11 · 585 阅读 · 0 评论 -
一个程序读懂指针常量、常量指针
char s1[]="abc"//可以被修改char s2[]="abc"s1==s2?s1不等于s2,两个没关系char *s1="abc"//不能被修改char *s2="abc"s1=s2两个指向同一个字符串,“abc”被保存在静态区const char * 表示常量,指针不能被修改,指针指向的内容也不能被修改。char const* 常量指针,指针可以被修改,指针指向的内...原创 2018-12-05 12:26:43 · 137 阅读 · 0 评论 -
在ubuntu上创建C++工程
一般一个C++工程包含如下东西:程序入口main()文件其他.h和.cppCMakeLists.txtmain()函数里包含.h文件.cpp要做成动态链接库或者静态链接库,通过add_library程序在执行的时候要链接动态链接库或者共享链接库。target_link_libraries()CMakeList.txt# 声明要求的 cmake 最低版本cmake_minimum...原创 2018-11-29 15:18:47 · 1362 阅读 · 0 评论 -
elas算法源码赏析(一):PGM格式图片的读取和保存
image.h源码来说说头文件pgm格式简约笔记// basic image I/O, based on Pedro Felzenszwalb's code#ifndef IMAGE_H#define IMAGE_H#include <cstdlib>#include <climits>#include <cstring>#include &...原创 2018-10-30 21:46:21 · 1204 阅读 · 0 评论 -
elas源码赏析(二)sobel算子3*3行列分解快速卷积
sobel3*3算子的计算过程_mm_malloc()convolve_cols_3x3 列卷积convolve_101_row_3x3 101的行卷积convolve_121_row_3x3 121的行卷积 void sobel3x3( const uint8_t* in, uint8_t* out_v, uint8_t* out_h, int w, int h ) { int16...原创 2018-10-31 22:51:52 · 2064 阅读 · 0 评论 -
PAT 1139. First Contact
1139. First Contact 这道题目注意点:1.用字符串读入人的编号,因为如果用int,当输入-0000和0000时无法判断性别2.用邻接表存图,为防止内存超限3.可能这个人要表白的人正好是他的朋友。4.两个set两层遍历的时候,for(it=a.begin();it!=a.end();it++)for(it1=b.begin();it1!=b.end();it1++)//#inclu...原创 2018-03-14 12:53:37 · 516 阅读 · 0 评论 -
构造回文(腾讯2017暑期实习生编程题)
题目:给定一个字符串s,你可以从中删除一些字符,使得剩下的串是一个回文串。如何删除才能使得回文串最长呢?输出需要删除的字符个数。输入描述:输入数据有多组,每组包含一个字符串s,且保证:1<=s.length<=1000.输出描述:对于每组数据,输出一个整数,代表最少需要删除的字符个数。输入例子:abcdagoogle输出例子:22题目:给定一个字符串s,你可以从中删除一些字符,使得...原创 2018-02-19 22:20:41 · 350 阅读 · 0 评论 -
棋盘游戏
时间限制:1秒 空间限制:65536K 热度指数:426 算法知识视频讲解题目描述 有一个6*6的棋盘,每个棋盘上都有一个数值,现在又一个起始位置和终止位置,请找出一个从起始位置到终止位置代价最小的路径: 1、只能沿上下左右四个方向移动 2、总代价是没走一步的代价之和 3、每步(从a,b到c,d)的代价是c,d上的值与其在a,b上的状态的乘积 4、初始状态为1...原创 2018-02-28 16:00:46 · 953 阅读 · 0 评论 -
无冗余字符串连接
时间限制:1秒 空间限制:65536K 热度指数:3277 算法知识视频讲解题目描述不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。输入描述:每一行包括两个字符串,长度不超过100。输出描述:可能有多组测试数据,对于每组数据,不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。输出连接后的字符串。示例1输入abc def输出abcdef...原创 2018-03-08 11:15:27 · 1450 阅读 · 0 评论 -
PAT To Fill or Not to Fill
链接:https://www.nowcoder.com/questionTerminal/4ad3d8cde8ca4889a32ed0a89edeefeb来源:牛客网[编程题]To Fill or Not to Fill (25)热度指数:666时间限制:1秒空间限制:65536K算法知识视频讲解With highways available, driving a car from Hangzho...原创 2018-01-23 22:10:16 · 229 阅读 · 0 评论 -
质因数的个数
题目描述求正整数N(N>1)的质因数的个数。 相同的质因数需要重复计算。如120=2*2*2*3*5,共有5个质因数。// pat.cpp : 定义控制台应用程序的//#include "stdafx.h"#include"stdio.h"#include<iostream>#include<cmath>using namespace std;in...原创 2018-02-13 17:35:17 · 594 阅读 · 0 评论 -
浮点数加法
时间限制:1秒 空间限制:65536K 热度指数:426 算法知识视频讲解题目描述求2个浮点数相加的和 题目中输入输出中出现浮点数都有如下的形式: P1P2...Pi.Q1Q2...Qj 对于整数部分,P1P2...Pi是一个非负整数 对于小数部分,Qj不等于0输入描述:对于每组案例,每组测试数据占2行,分别是两个加数。输出描述:每组案例是n行,每组测试数据有一行输出是相应的和。输出保证一定是一...原创 2018-02-26 19:43:09 · 803 阅读 · 0 评论 -
求一共有多少种最短路径时
void dij(int s){fill(d,d+n,inf);d[s]=0;way[s]=1;for(int i=0;iint min=inf,u=-1;for(int j=0;jif(vis[j]==0&&d[j]min=d[j];u=j;}}if(u==-1)return;vis[u]=1;for(int j=0;j{int v原创 2018-01-30 12:31:55 · 265 阅读 · 0 评论 -
一边遍历,一边删除迭代器的问题
map>::iterator it=co.begin();while(it!=co.end()){if(it->second==0)co.erase(it); it++;}不管删不删除,都是it++;原创 2018-01-30 11:37:17 · 959 阅读 · 0 评论 -
PAT Ranking
[编程题]PAT Ranking (25)热度指数:806时间限制:1秒空间限制:65536K算法知识视频讲解Programming Ability Test (PAT) is organized by the College of ComputerScience and Technology of Zhejiang University. Each test is sup原创 2018-02-05 22:19:14 · 218 阅读 · 0 评论 -
PAT Tree Traversals Again (25)
Tree Traversals Again (25)时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小)题目描述An inorder binary tree traversal can be implemented in a non-recursive way with a stack.原创 2018-01-29 19:35:59 · 189 阅读 · 0 评论 -
PAT Have Fun with Numbers
Have Fun with Numbers (20)时间限制 1000 ms 内存限制 655360 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小)题目描述Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from原创 2018-02-04 22:08:08 · 197 阅读 · 0 评论 -
PAT Read Number in Chinese
Given an integer with no more than 9 digits, you are supposed to read itin the traditional Chinese way. Output "Fu" first if it isnegative. For example, -123456789 is read as "Fu yi Yi er Qian sanBai原创 2018-01-28 13:51:55 · 231 阅读 · 0 评论 -
PAT Digital Library
[编程题]Digital Library (30)热度指数:548时间限制:2秒空间限制:655360K算法知识视频讲解A Digital Library contains millions of books, stored according to theirtitles, authors, key words of their abstracts, publishers原创 2018-02-03 12:37:05 · 192 阅读 · 0 评论 -
输出分数需要注意什么?
struct node{ll u,d;}c;simplify(c.u,c.d); if(c.u==0)cout<<"0"; else if(c.d==1)cout<<c.u; else{ if(abs(c.u)>c.d){ cout<<c.u/c.d<<" "<<abs(c.u%c.d原创 2018-01-28 11:53:08 · 136 阅读 · 0 评论 -
最小花费
时间限制:1秒 空间限制:65536K 热度指数:683 算法知识视频讲解题目描述在某条线路上有N个火车站,有三种距离的路程,L1,L2,L3,对应的价格为C1,C2,C3.其对应关系如下: 距离s 票价 0<S<=L1 C1 L1<S<=L2 C2 L2<S<=L3 C3 输入保证0<L1&...原创 2018-02-14 21:37:09 · 443 阅读 · 0 评论 -
最小邮票数
时间限制:1秒 空间限制:65536K 热度指数:2079 算法知识视频讲解题目描述 有若干张邮票,要求从中选取最少的邮票张数凑成一个给定的总值。 如,有1分,3分,3分,3分,4分五张邮票,要求凑成10分,则使用3张邮票:3分、3分、4分即可。输入描述: 有多组数据,对于每组数据,首先是要求凑成的邮票总值M,M<100。然后是一个数N,N〈20,表示有N张邮票。接下来是...原创 2018-02-13 17:52:19 · 229 阅读 · 0 评论 -
C/C++字符串中出现‘\’的情况
如果在字符串中出现'\',必须要用'\\'来代替举个简单的例子时间限制:1秒 空间限制:65536K 热度指数:511 算法知识视频讲解题目描述 A common typing error is to place the hands on the keyboard one row to the right of the correct position. So "Q" is typed as...原创 2018-02-28 12:41:50 · 4177 阅读 · 0 评论