
C语言基本算法
文章平均质量分 82
alotuscc
你和你的犬色声马,我和我的各安天涯。
千里走单骑,八方为敌。
青灯古佛度苍生,不愿度己。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
链表寻找环入口
链表寻找环入口#mermaid-svg-JWpRPnYJFwJDkcyw .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-JWpRPnYJFwJDkcyw .label text{fill:#333}#mermaid-svg-JWpRPnYJFwJDkcyw .node rect,#mermaid-svg-JW原创 2021-03-31 18:59:21 · 228 阅读 · 1 评论 -
C语言面对对象的一种简单写法
#include <stdio.h>#include <string.h>struct app{ int x; int y; char name[10]; void (*init)(struct app *thisptr, int _x, int _y, const char *_name); int (*calxy)(str...原创 2019-10-28 12:02:50 · 762 阅读 · 0 评论 -
Cleaning Shifts(贪心)
这题在贪心的时候需要注意一下技巧,否则就会超时。没有直接选取第一个点,而是比较之后选了最优的一个点。如果没有解直接结束。两个点之间是不连续的,所以第一次覆盖这个点之后,下一次可以直接从这个点+1开始。#include<iostream>#include<stdio.h>#include<string.h>#include <algorithm...原创 2019-03-22 10:15:54 · 511 阅读 · 0 评论 -
Monkey and Banana
#include <iostream>#include <algorithm>//#include <bits/stdc++.h>using namespace std;#define max(x, y) (x>y?x:y)#define min(x, y) (x<y?x:y)struct node{ int L;...原创 2019-03-21 01:21:51 · 144 阅读 · 0 评论 -
A* 求16宫格拼图
#include <QCoreApplication>#include <bits/stdc++.h>#include <iostream>#include <cstring>#include <stdio.h>using namespace std;#define N 4#define N2 16#define LI...原创 2019-03-12 13:05:31 · 971 阅读 · 0 评论 -
IDA* 求16宫格拼图
#include <QCoreApplication>#include <bits/stdc++.h>#include <iostream>#include <cstring>#include <stdio.h>using namespace std;#define N 4#define N2 16#define LI...原创 2019-03-12 08:56:31 · 485 阅读 · 0 评论 -
广度优先搜索求九宫格
#include <QCoreApplication>#include <bits/stdc++.h>#include <iostream>#include <cstring>#include <stdio.h>using namespace std;#define N 3#define N2 9struct Pu...原创 2019-03-12 00:20:02 · 763 阅读 · 0 评论 -
回溯法求八皇后
#include <QCoreApplication>#include <bits/stdc++.h>#include <iostream>#include <cstring>#include <stdio.h>using namespace std;#define N 8int row[N]; //四个方向int ...原创 2019-03-11 21:54:10 · 230 阅读 · 0 评论 -
二分求LIS
#include <bits/stdc++.h>#include <iostream>#include <cstring>#include <stdio.h>using namespace std;int L[10];int Length = -1;int N;int num;int BinFind(int Len[], i...原创 2019-03-11 11:28:09 · 382 阅读 · 0 评论 -
Corporative Network
#include &lt;bits/stdc++.h&gt;#include &lt;iostream&gt;#include &lt;cstring&gt;#include &lt;stdio.h&gt;using namespace std;int A[20010];int top[20010];int TT = 0;void L原创 2019-03-10 20:00:04 · 174 阅读 · 0 评论 -
线性扫描求最长连续子序列 。
扫描法求最长连续子序列。需要维护两个值,一个当前序列的最大值,一个总的序列的最大值。当前的序列的最大值为前面的(最大值+当前值)与(当前值)中的较大者。总的最大值为上一个总最大值与当前最大值中较大者。例如 45 -88 5 2 -8 -7 88 -9cur = 45 -43 5 7 -1 -1 88 88maxs =45 45 45 45 45 ...原创 2018-12-01 00:48:52 · 157 阅读 · 0 评论 -
线段树基本操作
线段树基本操作线段树的思想来自分治思想。首先求解两个子问题,问题的答案由两个子问题的答案得出。例如求一个区间的最值。可分别求出左半区间的最值,再求出右半区间的最值,区间的最值为两个最值的最值。而再求左半区间和右半区间时,又可以用分治。直到最后问题化简为最简单的问题,即区间只有一个数的情况。这时,最值便是他本身。线段树就是这种数据结构。可用于解决区间问题。线段树的叶子节点就是最简单的情况,即...原创 2018-12-01 00:24:39 · 297 阅读 · 0 评论 -
线段树求最长连续上升子序列
//#include <bits/stdc++.h>#include <iostream>#include <algorithm>#include <cstdio>using namespace std;struct Node{ int Pre, Suf; int PreSize, SufSize, SumSize, ...原创 2018-12-02 23:10:51 · 874 阅读 · 0 评论 -
Piggy-Bank
完全背包。。。#include <iostream>#include <algorithm>using namespace std;#define INF 0x3f3f3f3fstruct node{ int P; int W; bool operator <(const struct node &A) {...原创 2019-03-21 20:02:17 · 182 阅读 · 0 评论 -
Doing Homework
有n个任务,每个任务有一个截止时间,超过截止时间一天,要扣一个分。求如何安排任务,使得扣的分数最少。Input有多组测试数据。第一行一个整数表示测试数据的组数第一行一个整数n(1<=n<=15)接下来n行,每行一个字符串(长度不超过100)表示任务的名称和两个整数,分别表示任务的截止时间和完成任务需要的天数。 这n个任务是按照字符串的字典序从小到大给出。 Output...原创 2019-03-21 23:46:03 · 265 阅读 · 0 评论 -
Dividing the Path
思路:从左边往右边考虑,F[x]为区间[0,x]的解。因此所求为F[L]。首先可以推断出,以下几点x 为偶数,因为洒水是以原点为中心画圆,所有直径不可能为奇数。F[x] = F[y]min + 1, y = [x-2B, x-2A]。 因为半径为A——B,所有只有x-2B 到 x-2A 之间才能通过再加一个点达到x。那么如何快速求得[x-2B, x-2A]中的y,使得F[y]最小?需要...原创 2019-08-22 17:03:04 · 340 阅读 · 0 评论 -
Charm Bracelet
题目链接简单背包,需要使用滚动数组。#include <iostream>#include <vector>#include <string>#include <algorithm>#include <cmath>#include <limits.h>#include <iomanip>#incl...原创 2019-08-17 20:02:46 · 549 阅读 · 0 评论 -
神奇的口袋
题目链接背包dp[i][j] 表示从前j种物品里凑出体积i的方法数#include <iostream>#include <vector>#include <string>#include <algorithm>#include <cmath>#include <limits.h>#include <i...原创 2019-08-17 19:35:12 · 482 阅读 · 0 评论 -
最佳加法表达式
题目链接这题的思路很简单,dp[i][j] 代表前j个字符串使用i个 + 号所能组成的最小值。很明显,当i=0时,说明没有使用+号,最小值为前j个字符串。当i>=j时,很明显,此时构不成一个值,所有取maxstr当i<j时,dp[i][j] = min(dp[i-1][k]+substr(k, j-k)) (k= 1…j-1) 也就是由前k个字符串,i-1个+号所构成的...原创 2019-08-17 19:08:45 · 250 阅读 · 0 评论 -
Aggressive cows 基础二分
Aggressive cows思路:根据题目描述,我们需要求解ans的最大值,可以使用二分求解,范围为0-max.每次都尝试一下ans,如果尝试成功,说明右边区间[M+1, R]可能还有更大的解,如果尝试失败,就在区间[L, M+1]中继续尝试。#include <iostream>#include <vector>#include <string>...原创 2019-08-14 23:11:38 · 311 阅读 · 0 评论 -
Blocks
题目链接思路:dp[i][j][len] 表示从i到j个大块,并且右边有长度为len的与第j个块颜色相同的块。初始为dp[0][j][0]。从右边开始考虑,也就是从第j个块开始考虑,如果将第j个块直接消掉,结果为dp[i][j-1][0]+ (len[j]+len)*(len[j]+len)如果考虑左边有一个颜色块k与第j块相同能与之合并,结果为dp[i][k][len[k]+len] ...原创 2019-08-18 19:37:04 · 199 阅读 · 0 评论 -
磁砖样式 另一种思路的dfs
基本的dfs搜索一般都是直接从一个点出发,再从这个点到下一个但是这题使用了另一种思路的dfs每次选择点不是根据上一个点来推进,而是从整个地图中选择没有选过的点也就是扫描一遍地图,从中选择还没有使用过的点,这种方式往往用于两个点之间的转移规则比较复杂的情况,比如这题,每次需要使用两个点,而不是一个,同时有横竖两种方向。使用这种方式时需要注意在找到第一个点之后需要立即return。#incl...原创 2019-05-09 11:13:15 · 196 阅读 · 0 评论 -
HDOJ 6463 超级无敌简单题
#include <bits/stdc++.h>#include <hash_map>using namespace std;using namespace __gnu_cxx;#pragma GCC optimize(2)#define maxx 150000hash_map<int, bool> M;int Ans[150010];in...原创 2019-04-16 00:45:29 · 212 阅读 · 0 评论 -
HDOJ 6464
先离线,离散化在线段树维护区间和以及数量#include <bits/stdc++.h>using namespace std;///#pragma GCC optimize(2)#define Mode 1000000007const int N = 1<<17;struct node{ long long Sum; long lo...原创 2019-04-15 23:21:23 · 173 阅读 · 0 评论 -
C语言字符串与变量名的转换
#include #include #include <string.h>#include #include<stdio.h>using namespace std;#define to_str(name) (#name)#define TIMx_ARR(n) TIM##n##_ARRint main(void){freopen(“G:\data.tx...原创 2019-04-03 23:11:10 · 9399 阅读 · 0 评论 -
利用线段树求最大连续子序列和
#include &amp;amp;lt;bits/stdc++.h&amp;amp;gt;using namespace std;struct Node{ int Pre, Max, Suf,Sum; int Left, Right;};struct Node SegTree[100];int c[100] = {0,45,-88,5,2,-8,-7,88,-9};void Built...原创 2018-12-02 15:58:52 · 586 阅读 · 0 评论 -
ACM八皇后详解
会下国际象棋的人都很清楚:皇后可以在横、竖、斜线上不限步数地吃掉其他棋子。如何将8个皇后放在棋盘上(有8 * 8个方格),使它们谁也不能被吃掉!这就是著名的八皇后问题。思路:要求在8*8的方格中放置8个皇后。稍加分析知道,必定是每行放一个。采用回溯算法。从第一行开始。依次遍历8列。检查该点是否可以放置皇后。如果可以放置,放置完成后,直接递归到下一行。继续以相同的方式检查。函数回溯的时候有两种...原创 2018-10-27 23:39:02 · 1678 阅读 · 0 评论 -
gcd求最大公约数
gcd(M,N) = 1. M%N = 0 : N2. M%N=R, R>0 : gcd(N, R)这里不做过多解释。int ggcd[100][100];int gcd(int M, int N){ if(ggcd[M][N] != 0) return ggcd[M][N]; int R = M%N; if(R == ...原创 2018-10-26 22:24:29 · 412 阅读 · 0 评论 -
二项队列的建立及其基本操作
#include <stdio.h>#include<stdlib.h> //二项队列支持合并,插入,删除最小值等操作,且每次操作最坏花费log N //二项队列不是一个堆序,而是一群堆序的集合#define Infinity 10000#define MaxTrees 14 /...原创 2018-06-05 01:35:47 · 486 阅读 · 0 评论 -
队列的数组实现及其基础操作
#include<stdio.h>#include<stdlib.h>typedef int ElementType ; struct QueueRecord{ int Capacity; int Front; int Rear; int Size; ElementType *Array;};typedef struct QueueRecord *Queue; int Is...原创 2018-05-28 19:01:03 · 859 阅读 · 0 评论 -
归并排序
#include <stdio.h>#include<stdlib.h>typedef int ElementType;void MSort(ElementType A[],ElementType TmpArry[],int Left,int Right);void MergeSort(ElementType A[],int N);void Merge(ElementTyp...原创 2018-06-11 12:39:14 · 165 阅读 · 0 评论 -
栈的简单应用之括号匹配
#include<stdio.h>#include<stdlib.h>#include<string.h>#define EmptyTOS (-1)#define MinStackSize ( 5 )typedef char ElementType ;struct StackRecord{ int Capacity; int TopOfStack;...原创 2018-05-28 00:18:52 · 262 阅读 · 0 评论 -
栈的顺序储存及基本操作
#include<stdio.h>#include<stdlib.h>#define EmptyTOS (-1)#define MinStackSize ( 5 )typedef int ElementType ;struct StackRecord{ int Capacity; int TopOfStack; ElementType *Array;};ty...原创 2018-05-27 23:00:58 · 1538 阅读 · 0 评论 -
左式堆的建立及其基本操作
#include <stdio.h>#include<stdlib.h>typedef int ElementType;struct TreeNode;typedef struct TreeNode *PriorityQueue;PriorityQueue Initialize(ElementType X); ...原创 2018-06-03 21:35:25 · 295 阅读 · 0 评论 -
栈的建立和一些基本操作
栈作为一种数据结构,由线性表演变而来,具有后进先出特性,有顺序储存和链式储存两种写法,这里写的是链式储存#include<stdio.h> #include<stdlib.h> typedef int ElementType; struct Node{ ElementType Element; struct Node *Next;};typedef struct Nod...原创 2018-05-27 19:44:59 · 4954 阅读 · 0 评论 -
最小堆的大建立及其一些基本操作
#include <stdio.h>#include<stdlib.h>typedef int ElementType;ElementType MinDate = -10000 ;struct HeapStruct;typedef struct HeapStruct *PriorityQueue;PriorityQueue Initialize(int Maxelement...原创 2018-06-03 16:05:28 · 315 阅读 · 0 评论 -
简单链表的建立以及一些基本操作
#include<stdio.h>#include<stdlib.h>typedef int ElementType ; // ElementType 可以定义为其他类型 struct Node{ ElementType Element; struct Node *Next;};typedef struct Node *PtrToNode;typedef Ptr...原创 2018-05-25 22:34:21 · 301 阅读 · 0 评论 -
快速幂运算
快速幂基本原理: X^62 = (X^31) ^2 X^31 = (X^15) ^2 * X X^15 = (X^7) ^2 * X X^7 = (X^3) ^2 * X X^3 ...原创 2018-05-25 12:43:47 · 228 阅读 · 0 评论 -
欧几里得算法
欧几里得算法基本思想: Gcd(a,b) = Gcd(b , a%b) 直到最后余数为0例如 Gcd(70,15) = Gcd(15,10) 70%15 = 10 Gcd(15,10) = Gcd(10,5) 15%10 = 5 Gcd(10,5) = Gcd(5,0) 10%5 ...原创 2018-05-25 11:12:39 · 412 阅读 · 0 评论 -
二叉查找树及其基本操作
#include<stdio.h>#include<stdlib.h>typedef int ElementType;struct TreeNode{ ElementType Element; struct TreeNode *Left; struct TreeNode *Right;};typedef struct TreeNode *Position;typedef s...原创 2018-05-29 19:03:09 · 275 阅读 · 0 评论