自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(13)
  • 问答 (1)
  • 收藏
  • 关注

原创 Linux 利用POSIX多线程API函数进行线程同步

参考:《Linux c与c++一线开发实践》朱文伟 李建英将书上代码敲了一下,存在这里以便后续开发参考一、互斥锁定义互斥锁pthread_mutex_t mutex;互斥锁初始化(动态方式)int pthread_mutex_init(pthread_mutex_t *restrict mutex,const pthread_mutexattr_t *restrict attr);关键字restrict只用于限定指针,用于告知编译器所有修改该指针所指向的内容的操作全部都是基于该指针的,即不存在其

2021-03-21 21:10:12 206

原创 牛客网 KY191 矩阵幂

#include <iostream>using namespace std;struct Matrix { int matrix[10][10]; int row, col; Matrix(int r, int c):row(r),col(c){}};Matrix Multiply(Matrix x, Matrix y) { Matrix answer(x.row, y.col); for (int i = 0; i < answer.row; ++i) {

2021-03-20 13:34:33 106

原创 Linux C++11中线程类

参考:《Linux c与c++一线开发实践》朱文伟 李建英将书上代码敲了一下,存在这里以便后续开发参考一、类std::thread常用成员函数成员函数说明thread构造函数get_id获得线程IDjoinable判断线程对象是否可结束join阻塞函数,等待线程结束native_handle用于获得与操作系统相关的原生线程句柄swap线程交换detach分离线程二、线程的创建1.批量创建线程#include <std

2021-03-16 22:58:52 181

原创 Linux 利用POSIX多线程API函数进行多线程开发

与线程有关基本API函数API函数含义以上函数需要包含头文件pthread.h线程创建int pthread_create(pthread_t *pid, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)其中,pid是一个指针,指向创建成功后的线程ID;pthread_t其实就是unsigned long int;attr是指向线程属性结构

2021-03-15 21:42:03 265

原创 linux进程间通信 实例:使用kill发送信号终止目标进程

参考列表waitpid(…)函数:https://blog.csdn.net/yiyi__baby/article/details/45539993exit(…)函数:https://blog.csdn.net/u010006102/article/details/39737155代码参考:《Linux c与c++一线开发实践》朱文伟 李建英自学笔记c语言代码#include <sys/types.h>#include <sys/wait.h>#include &lt

2021-03-08 22:59:49 225 1

原创 牛客网 KY105 整除问题

参考下述解法:1.素数筛2.对n!质因子分解算法3.对a质因子分解算法int nFac[MAXN]={0};//记录n!的质因数分解后的结果,n!存在质因数i,则aFac[i]=指数int aFac[MAXN]={0};//记录a的质因数分解的结果,a存在质因数i,则aFac[i]=指数比较n!和a的相同质因数的指数相除的最小值为所求。例如:6!=24+32+5^110=21*51有公共质因数:2 指数相除为4/1=45 指数相除为1/1=1所以答案为1这里是将a质因子分解后在n

2021-03-05 19:38:09 207

原创 牛客网 KY3 约数的个数

约数即因子,质数,约数类题目先想到用所给数开根号来缩小循环次数,简化计算,对于本题,以sqrt(num)为界,若比它小有一个因子,则比它大一定存在另一个因子,此时结果加2,最后再判断sqrt(num)是否为其一个因子若是则结果加1,即可。程序代码#include <iostream>using namespace std;int main(){ int n; while (cin >> n) { for (int i = 0; i < n; ++i) {

2021-03-05 12:25:23 115

原创 牛客网 KY183 素数

#include <iostream>#include <vector>#include <cmath>using namespace std;int main(){ long long n; while (cin >> n) { vector<int> re; //所有素数存放在这里 for (int j = 2; j < n; ++j) { bool t = true; for (in

2021-03-04 19:47:31 200 2

原创 牛客网 KY235 进制转换2

#include <iostream>#include <cstring>#include <vector>#include <sstream>using namespace std;string mul(string a, int b) { //字符串乘法 int carry = 0; for (int i = a.size() - 1; i >= 0; --i) { int current = carry + (a

2021-03-04 16:27:28 165 2

原创 动态规划 最长上升子序列 学习笔记

题目描述递推公式程序代码#include <iostream>#include <algorithm>using namespace std;const int MAXN = 100;int main(){ int a[MAXN]; int maxLen[MAXN]; int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; maxLen[i] =

2021-03-03 19:12:54 49 2

原创 牛客网 KY26 10进制 VS 2进制

#include <iostream>#include <vector>using namespace std;string divide(string str, int x) { //字符串除法 int remainder = 0; for (int i = 0; i < str.size(); ++i) { int current = remainder * 10 + str[i] - '0'; str[i] = current / x + '

2021-03-03 16:07:13 123 2

原创 牛客网 KY30 进制转换

思路对输入字符串对2取模再除以2,对于字符串取模运算,转换为对字符串最低位数进行取模;字符串除法则是把字符串从高到低逐位除以除数,如果不能整除,那么保留它除以除数的余数,余数乘10后和低位相加后一起处理,由于有前置0,故应取首个非0位之后的字符。程序代码#include <iostream>#include <vector>using namespace std;int qu_yu(string a) { //取余 return (a[a.length() -

2021-03-03 12:09:57 102

原创 牛客网 KY187 二进制数

位运算#include <iostream>using namespace std;void calculate(int n) { int temp = n & 1; if (n == 0) return; calculate(n >> 1); cout << temp;}int main(){ int n; while (cin >> n) { calculate(n); cout << endl

2021-03-02 23:55:10 188

空空如也

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

TA关注的人

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