lzhenf

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

随笔分类 -  sicily算法

摘要:#include <stdio.h>#include <algorithm>#include <memory.h>using namespace std;int result[1001][101];int w[101],v[101];int main(){ int totalTime , count; memset(result , 0 ,sizeof(result)); scanf("%d %d" , &totalTime , &count); for ( int i = 1 ;i <= count ; i++) 阅读全文
posted @ 2012-03-20 00:05 lzhenf 阅读(357) 评论(0) 推荐(0)

摘要:1 #include <iostream> 2 #include <map> 3 #include <vector> 4 #include <string> 5 #include <queue> 6 using namespace std; 7 const int MaxNum = 203; 8 const int MAX = 999999; //定义一个较大的数 , 用于松弛处理 9 //定义距离数组10 int dis[MaxNum];11 int n ; //节点的数目 : n+ 1 12 typedef pair<int 阅读全文
posted @ 2011-12-27 23:32 lzhenf 阅读(290) 评论(0) 推荐(0)

摘要:1 #include <stdio.h> 2 #include <vector> 3 #include <iostream> 4 using namespace std; 5 6 7 const int NumNode = 8 ; 8 vector<int> v[9]; 9 enum colors10 {11 white , black , gray 12 }color[NumNode + 1];13 void dfs( int i )14 {15 color[i] = gray ;16 cout << i << endl 阅读全文
posted @ 2011-12-27 00:04 lzhenf 阅读(240) 评论(0) 推荐(0)

摘要:// 以1 为起点 ,广度优先搜索 , 图是有连通,有环的 ,所以要标记颜色 , 白色代表 未访问 , 灰色代表 已进入队列 , 黑色代表访问完 。#include <stdio.h>#include <vector>#include <queue>#include <iostream>using namespace std ;enum colors { white , gray , black } ;colors color[10] ;vector<int> v[9] ;void bfs(){ queue<int> q 阅读全文
posted @ 2011-12-24 16:59 lzhenf 阅读(702) 评论(0) 推荐(0)

摘要:1 /* 2 线性时间求出1-N 的素数 , 时间复杂度为O( N) ; 3 一个合数可以表示成若干个素数的积 4 比如说 i = 6 =2 * 3 , A = p1 * p2 * p3 .. * pn , 其中pi为素数 ,p1最小 , 只筛到p1 * i即可 5 我们只筛 最小的 2 * i 不筛3 * i ; 6 */ 7 #include <stdio.h> 8 #include <memory.h> 9 const int MaxNum = 100000;10 11 12 bool isPrime[MaxNum] ; //数组定义该数字是否为素数 13 int 阅读全文
posted @ 2011-12-24 13:24 lzhenf 阅读(3120) 评论(0) 推荐(0)

摘要:C/C++语言提供的位运算符有:运算符含义功能&按位与如果两个相应的二进制位都为1,则该位的结果值为1;否则为0。|按位或两个相应的二进制位中只要有一个为1,该位的结果值为1。∧按位异或若参加运算的两个二进制位同号则结果为0(假)异号则结果为1(真)~取反~是一个单目(元)运算符,用来对一个二进制数按位取反,即将0变1,将1变0。<<左移左移运算符是用来将一个数的各二进制位全部左移N位,右补0。>>右移表示将a的各二进制位右移N位,移到右端的低位被舍弃,对无符号数,高位补0。1.判断奇偶1 bool isOdd( int num )2 {3 return ( n 阅读全文
posted @ 2011-12-22 20:25 lzhenf 阅读(226) 评论(0) 推荐(0)

摘要:1 // source code of submission 1098949, Zhongshan University Online Judge System 2 /* 3 2014 sicily 4 完全背包问题 5 把硬币看成一件一件来的物品 , 数量不限 ,面值看成其cost , 6 填充进cost总和为总面值V, 7 代码编写风格参考背包九讲 8 */ 9 #include <stdio.h>10 #include <memory.h>11 int V , dp[301];12 int value[9];13 14 15 void ZeroOnePack( i 阅读全文
posted @ 2011-12-20 21:42 lzhenf 阅读(161) 评论(0) 推荐(0)

摘要:/*sicily 一道找中位数的题目 条件限制是内存小 , 不足以存下全部数字 2M的内存空间 , 最大数目去到 500000 ;初略估算 : 一个Int 4个字节 4 * 500000 = 2000000个字节 , 1MB = 1024 * 1024 个字节 = 1048576个字节 2Mb就是 208000个字节 , 如果把所有数字都存放的话 , 在没有空间运行程序了 。因此考虑建一个堆 , 但是堆的大小只有 N/2 , 这样的话 , 还有1MB的运行空间 , 当后一半数据输入的时候,动态把堆的其中无用节点弹出,新的数值插入堆。*/#include <stdio.h>#incl 阅读全文
posted @ 2011-12-15 23:06 lzhenf 阅读(440) 评论(0) 推荐(0)

摘要:1 #include <stdio.h> 2 #include <iostream> 3 using namespace std; 4 const int cmax = 100005; 5 const int minnum = -999999999; 6 int ans , s , x , posx , posy ; 7 struct Tnode 8 { 9 10 int maxs , sum , maxl , maxr ; // maxs为当前区间最大的序列和 , sum为当前区间的和 , maxl为当前区间左端点开始的最大序列和 , maxr 11 ... 阅读全文
posted @ 2011-12-15 11:25 lzhenf 阅读(398) 评论(0) 推荐(0)

摘要:n由于两个子线段是尽量平均的,因此长度为N的线段树的深度为O(logN)。n给定一个叶子p, 从根到p路径上所有结点(即p的所有直系祖先)代表的线段都包含点p, 且其他结点代表的线段都不包含点p。n对于每个线段,都可以看作O(logN)条线段的并,且每两条线段间不存在公共部分。(分治思想)线段树的写法:/*线段树的基本结点结构,[l,r]表示这个结点所代表的线段,left和right分别指向左右儿子。*/ struct node { int l, r; node *left, *right; // something else};线段树建立 :node* build(int l,int ... 阅读全文
posted @ 2011-12-15 11:21 lzhenf 阅读(241) 评论(0) 推荐(0)

摘要:1 /* 2 K路归并排序 , 3 主要思想 : 4 建立K路链表 , 在K路的最小元素提取出来 。 5 存储到 result数组中 , 利用result数组构造最小堆 , 6 每次取出堆顶的元素 , 在把取出的元素的那路的next填充到堆顶中, 重新维持堆特性 7 通过每次取出堆顶 ,知道K路链表均被取完 ,完成归并排序 8 */ 9 #include <stdio.h> 10 #include <algorithm> 11 #include <memory.h> 12 13 using namespace std; 14 //定义链表节点 15 stru 阅读全文
posted @ 2011-12-15 11:01 lzhenf 阅读(1644) 评论(0) 推荐(0)