- 博客(17)
- 收藏
- 关注
原创 01bag problem measure1:most easiest way to find the answer.measure2:use the easier way to solve
i travel the whole binary tree.#include<iostream> #include<stdio.h> #define Max_N 100 using namespace std; int res=0,Max=0; int N,W; int t[Max_N][2]; void fun(int i,int j) { if(i==N) ...
2018-03-23 16:10:00
255
原创 数据结构3.11答案 递归的查询单链表的其中的记录,以及最大能够让堆栈crash的值
#include #include typedef struct Node { Node *next; int data; } *List; void Init(List &l,int n) { Node *p,*current; p=(List)malloc(sizeof(Node)); p->data=1; p->next=NULL; l
2017-12-01 13:31:49
300
原创 约瑟夫环双向列表之终极优化
#include #include typedef struct Node { Node *pre; Node *next; int data; } *List; void Init(List &l,int n) { Node *p,*current; p=(List)malloc(sizeof(Node)); p->pre=NULL;
2017-12-01 12:12:44
327
原创 pthread.h写一个多线组织计算矩阵乘法的函数
有一个重点,就是在传递参数的时候由于需要传递两个参数,所以应该构造一个结构体,然后把这个结构体的地址传递给pthread_create()函数当中,在runner()函数当中的如何获取这个结构体呢,就是定义一个结构体指针,然后赋值为这个地址,通过->就能取得其中的参数。 #include #include #define M 3 #define K 2 #
2017-11-25 14:50:25
702
1
原创 父进程利用fork()函数创建子进程并且利用shared_memory进行通信的实例
#include #include #include #include #define Maxsize 10 typedef struct { int a[Maxsize]; int length; }A; int main() { int segment_id,fp; A* shared_mem; segment_id=shmget(IPC_PRIVATE
2017-11-17 20:20:28
1393
原创 区间问题
贪心算法即可#include #include #include using namespace std; const int Maxn=100000; typedef pair p; p c[Maxn]; int cmp(const p &a,const p &b) { if(a.second<b.second) return 1; else return 0;
2017-10-25 09:08:17
280
原创 硬币问题2.2(1)
#include using namespace std; #include int main() { int m[6]={1,5,10,50,100,500}; int n[6]; int total=0; for(int i=0;i<6;i++) { scanf("%d",&n[i]); } scanf("%d",&tot
2017-09-20 16:31:51
240
原创 广度优先寻找迷宫!
#include using namespace std; #include #include const int INF=1000000000; typedef pair P; char maze[105][105]; int d[105][105]; int n,m; int sx,sy; int gx,gy; int dx[4]={1,0,-1,0}; int dy[4]={0,-1,0,1
2017-08-01 17:16:23
268
原创 Lake Counting POJ - 2386
#include #include using namespace std; char t[105][105]; int n,m; void dfs(int x,int y) { t[x][y]='.'; int nx,ny; for(int dx=-1;dx<=1;dx++) { for(int dy=-1;dy<=1;dy++)
2017-08-01 13:23:24
252
原创 Ants POJ - 1852
#include #include #include //int pos[1000050]; using namespace std; int main() { int l,n,t,m; scanf("%d",&t); for(int i=1;i<=t;i++) { int min1=0,max1=0; scanf("%d%d",&l
2017-07-25 15:42:13
268
原创 uva 213 信息解码还是挺符合人的认知 有注释可以看看
#include using namespace std; #include #include #include #include char chr[8][1<<8]={'\0'}; void inch(string s)//good!!!! { memset(chr,'\0',sizeof(chr)); int flag=0; int len=s.length();//定
2017-05-15 10:00:16
303
原创 Rectangle
#include using namespace std; #include #include char sum[10000]; int flag=0; int weishu(long long n) { int zhi=0; while(n!=0) { n=n/10; zhi++; } return zhi; } void
2017-05-05 08:44:19
380
原创 huffman树 自己实现的大家可以看一看
这是我自己实现的霍夫曼树,我觉得大家需要注意的最主要的问题就是使用优先队列的话,你每往里面插入一个对象的话就会生成一个新的对象这个时候你的地址就发生变化了,所以我直接开了一个全局变量的element的数组,然后每一个element直接保存了自身的地址,这让你插入优先队列的话就不会发生问题了,就算插入之后地址发生了变化,但是你有myself这个指针保存着自身的地址,所以说,当两个节点需要合并的时候,就可以解决地址发生变化的问题了。
2017-05-03 23:57:55
337
原创 prim算法
#include<iostream> using namespace std; #include<stdio.h> const int maxn=100; bool s[maxn]; int lowcost[maxn]; int closest[maxn]; int c[maxn][maxn]; void prim(int n) { int total=0; ...
2017-05-03 11:41:52
416
转载 Kruskal算法 留给自己进行使用,如有侵权请告知删除
#include using namespace std; #include #include #include const int maxn=101; struct edge { int from; int to; int cost; friend bool operator <(const edge &e1,const edge &e2) {
2017-05-03 08:53:08
1241
4
原创 快速排序问题
快速排序问题是一个时间复杂度为O(nlgn)的算法,下面就是快速排序的具体实现的过程,希望大家能够给一些建议。 下面我们来研究一下最坏情况下这个算法的时间复杂度,以及什么是这个算法的最坏情况。 1.最坏情况的分析,最坏情况就是partition划分的过程当中,因为其时间复杂度为O(n),而每一次花分都是一边n-1另一边是1,所以这个时候 T(n)=T(n-1)+O(n),所以总的来说时间复杂
2017-04-19 16:46:26
475
原创 循环赛日程问题
循环赛日程问题,树上在讲分治法,但是算法的实现确是用循环来实现的,我们用递归来实现这一个算法,比较简单,但是希望大家看完给一点意见。 #include using namespace std; #include void Copy(int **a,int n,int x1,int y1,int x2,int y2) { for(int i=0;i {
2017-04-19 15:39:31
442
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅