- 博客(13)
- 收藏
- 关注
原创 方阵原地转置(C语言)
假设一个方阵按行优先储存在一维数组matrix中,将其原地转置:void SqrMaTranspose(double * matrix, int n){ double temp = 0.0; for(int i=0; i<n; i++){ for(int j=i+1; j<n; j++){ temp = matrix[i*n+j]; matrix[i*n+j] =
2022-04-06 09:57:22
508
原创 蒙特卡洛模拟-蚂蚁爬格子
An ant is trying to get from pointAto pointBin a grid; see Figure 2. The coordinates of pointAis(1,1)(this is top left corner), and the coordinates of pointBis(n,n)(this is bottom right corner,nis the size of the grid).Once the ant starts m...
2022-03-04 10:06:59
615
原创 C语言伪随机序列生成函数Pseudo-random sequence generation functions
C语言标准ISO/IEC 9899中的说明:1. The rand functionSynopsis#include<stdlib.h>int rand(void);DescriptionThe rand function computes a sequece of pseudo-random integers in the range 0 to RAND_MAX.rand函数生成大小在0到RAND_MAX之间伪随机整数序列。The rand function i
2022-03-03 10:39:50
1145
原创 Leetcode第647题 回文子串(中心扩展法+Manacher算法)
/* Leetcode第647题 回文子串 *给定一个只由小写英文字母组成的字符串s, 统计并返回这个字符串中回文子串的数目。 *子字符串是字符串中的由连续字符组成的一个序列。 *具有不同开始位置或结束位置的子串,即使是由相同的字符组成,也会被视作不同的子串。 *示例:输入s="aaa",输出6,6个回文子串为"a","a","a","aa","aa","aaa" */ #include<iostream> #include&...
2022-02-24 21:56:31
212
原创 LeetCode第1996题 游戏中弱角色的数量(C++)
#include<iostream>#include<algorithm>#include<vector>using namespace std;class Solution{ public: int numberOfWeakCharacters(vector<vector<int>>& properties){ int res = 0; sort(properties.beg...
2022-01-28 13:36:44
2649
原创 DCT离散余弦变换(C语言)
MATLAB Image Processing Toolbox中自带有dct2函数实现离散余弦变换,帮助文档解释如下:C语言版本实现如下:/*Remind: The caller must call free to release memory !!!*/#include<stdlib.h>#include<math.h> //必须使用math库#define PI acos(-1) //预定义PI值,C语言没有自带PIfloat ** dct2
2022-01-27 16:44:32
929
1
原创 按字节输出int类型变量(C语言)
#include<stdio.h>int main(void){ int a = -12; int mSize = sizeof(a); printf("a=%d, sizeof(a)=%d.\n", a, mSize); printf("size of int is %ld.\n", sizeof(int)); unsigned char *p = (unsigned char*) &a; //一定要用unsigned char * !!!.
2022-01-26 19:53:56
2810
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人