![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
简单算法
文章平均质量分 76
Yjiokm
记录一些我不熟的东西方便以后来查
展开
-
十六进制数转十进制数
十六进制数转十进制数,a~f不区分大小写#include #include #include #include int main(){ using namespace std; string s("ffff"); for(int i = 0; i < s.size(); i++) s[i] = toupper(s[i]); int ans = 0; for(int i原创 2016-05-24 13:04:13 · 305 阅读 · 0 评论 -
栈实现的图邻接矩阵深度优先遍历
#include #define N 6// 深度优先遍历void DFS_Traverse(bool adjmatrix[][N], int v0, void (*f)(int)){ bool visited[N] = {true};// v0设为已访问 int stack[N] = {v0};// 栈添加v0 int size = 1; f(v0); while (size原创 2016-10-09 21:40:15 · 1844 阅读 · 0 评论 -
日期作差
// 1、编写一个程序,求用户输入的开始时间到终止时间之间相距的天数。(本题15分)#include struct Date{ int year; int month; int day;};// 判断是否为闰年bool is366(int year){ return year % 100 == 0 && year % 400 == 0 || year % 100 != 0原创 2016-11-29 20:48:48 · 292 阅读 · 0 评论 -
判断二维线段相交
#include typedef struct Point {float x, y;} Vector;struct Line {Point p1, p2;};bool iscross(const Line & l1, const Line & l2, Point * pOut = nullptr){ Vector v1 = {l1.p2.x - l1.p1.x, l1.p2.y -原创 2016-11-29 21:36:30 · 406 阅读 · 0 评论 -
D3D11四面体简单方向光光照渲染
初始化设备大致分这几个步骤:1.Create device2.Create swap chain3.Create a render target view4.Create depth stencil texture5.Create the depth stencil view6.Setup the viewport7.Compile and create the ver原创 2016-12-12 13:36:32 · 1089 阅读 · 0 评论 -
四面体简单光照渲染+漫游(使用多个ConstantBuffer减小带宽)
建立了三个ConstantBuffer,一个是每一帧都需要从cpu传过来的用来旋转的world矩阵,一个是摄影机操作后传过来的view矩阵,还有一个是只传过来一次的projection矩阵和两个方向光的向量1.lighting.fx// Constant Buffer Variablescbuffer CBChangesEveryFrame : register( b0 ){ mat原创 2016-12-13 13:15:47 · 1848 阅读 · 0 评论 -
douglas peucker递归分治
vs2015 c++11 standard or later1. geometry.h#ifndef GEOMERTY_H_#define GEOMETRY_H_#include union Point{ struct { float x, y; }; float compo[2];};typedef std::deque PointList;#e原创 2017-02-26 17:23:33 · 432 阅读 · 0 评论 -
归并排序(非递归)
#include #include using namespace std;// 要求[i1, j1], [i2, j2]两段已经排序template void _merge(T a[], unsigned i1, unsigned j1, unsigned i2, unsigned j2){ if (i2 == i1) return; unsigned pos = i1原创 2017-03-11 12:45:38 · 367 阅读 · 0 评论 -
幂集问题(即求全组合,全部子集问题)
8、若S是n个元素的集合,则S的幂集P(S)定义为S的所有子集的集合。例如,S=(a,b,c),P(S)={(),(a),(b),(c),(a,b),(a,c),(b,c),(a,b,c)}。给定S,写一递归算法求P(S)。(本题20分)#include #include // 《数据结构》严蔚敏P150 例6.3void PrintPowerSet(int i, int n){原创 2016-11-30 14:42:49 · 1420 阅读 · 0 评论 -
Prim最小生成树
1. 静态的示意 由N个顶点的无向连通图生成最小生成树的各条边放在容量为N - 1的数组中。#include #include #define N 6//N个顶点struct Edge {int i; int j; int w;};//i: 起点下标 j: 终点下标 w: 权//int (*adjmatrix)[N]: 邻接矩阵行地址//Edge edge[N - 1]: 输原创 2016-09-15 15:22:59 · 179 阅读 · 0 评论 -
由数组创建二叉树,二叉树遍历,获取深度,销毁
先序遍历:A->B->D->E->C中序遍历:D->B->E->A->C后序遍历:D->E->B->C->A#include typedef char ElemType;#define EndElem '^'//用^来表示空typedef struct BiNode{ ElemType elem; struct BiNode * lchild; struct B原创 2016-09-01 11:21:05 · 443 阅读 · 0 评论 -
最简单逻辑迷宫求解
#include #include #define ROW 6#define COL 6int a[ROW][COL] = { 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1};//1:通路; 0:障碍s原创 2016-08-22 15:34:58 · 475 阅读 · 0 评论 -
点线段的距离函数
点线段的距离函数#include #include struct POINT{ double x; double y;};typedef POINT VECTOR;struct SEGMENT{ POINT * pStart; POINT * pEnd;};class Segment{public: POINT * pStart; POINT * pEn原创 2016-05-24 13:28:41 · 354 阅读 · 0 评论 -
最小凸包
1. 硬币法,存在问题:按顺时针排序,如果Pn, Pm, pP0共线如何处理?(比如{0, 10}, {5, 0}, {10, 0}三点凸包如何处理,{5, 0}是不是凸包上的点)#include #include #include struct POINT{ double x; double y;};typedef POINT VECTOR;class{public原创 2016-05-24 13:59:37 · 1062 阅读 · 0 评论 -
中位中心栅格遍历法
中位中心栅格遍历法#include #include namespace geo{ struct POINT { double x; double y; }; //栅格法寻找中位中心 POINT GetMedianCentre(const POINT * pts, int n, double d/*设置栅格化格网宽度*/) { double min_x = p原创 2016-05-24 13:15:41 · 1371 阅读 · 1 评论 -
简单的二维平面漫游
效果如下:鼠标中间拖动,滚轮缩放这是一个MFC基于对话框的应用程序,这里只讲述绘制(如设备坐标逻辑坐标换算及人机互动的消息映射)不讲图元储存等数据结构的问题,计算不牵涉线性代数,只是利用小学数学的知识,所以可能看起来杂乱,核心部分如下:1. 创建的工程名为Demo1605262. 添加图元类头文件"Primitive.h"(这里就以点为例了)#ifndef PR原创 2016-05-27 16:54:53 · 596 阅读 · 0 评论 -
Delaunay三角网
三角网生长法(课本上的方法按原意实现)//控制台演示#include #include #include #include #include #define PI 3.14159struct POINT{ double x; double y;};typedef POINT VECTOR;struct SEGMENT{ POINT * p_begin; P原创 2016-06-06 13:33:54 · 2807 阅读 · 0 评论 -
C语言单向链表
单链表#include #include struct Node{ char ch; Node * next;};struct CharList{ Node * head; Node * tail; Node * prev;};void InitCharList(CharList * list){ list->head = list->tail = list->p原创 2016-07-04 11:11:11 · 390 阅读 · 0 评论 -
链式存储的二叉树的操作思想示意
树的遍历,获取深度#include #define ADT floattypedef struct TNode{ struct TNode * parent;//父结点 struct TNode * lchild;//左子树 struct TNode * rchild;//右子树 ADT value;} * BinTree;void SetTNode(TNode * p原创 2016-07-17 15:16:48 · 331 阅读 · 0 评论 -
n×n棋盘上n皇后问题
code:// N Queen Problem: n queen, n row, n colomn, all possible queen placements.#include #include #define VALID 0#define INVALID -1#define QUEEN 1void create_board(int **& board, int n){原创 2017-04-06 18:11:31 · 451 阅读 · 0 评论