上一页 1 ··· 4 5 6 7 8 9 10 11 下一页
摘要: 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2421利用最小生成树求出总权值×2 - 最大的叶子节点所经路径的权值View Code 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define inf 0x3f3f3f 5 using namespace std; 6 int b[110][110]; 7 void prim(int n) 8 { 9 int 阅读全文
posted @ 2012-08-22 20:48 琳&leen 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 转自:http://www.cppblog.com/shyli/archive/2007/04/06/21366.html优先队列用法在优先队列中,优先级高的元素先出队列。标准库默认使用元素类型的<操作符来确定它们之间的优先级关系。优先队列的第一种用法,也是最常用的用法:priority_queue<int>qi;通过<操作符可知在整数中元素大的优先级高。故示例1中输出结果为:9 6 5 3 2第二种方法:在示例1中,如果我们要把元素从小到大输出怎么办呢?这时我们可以传入一个比较函数,使用functional.h函数对象作为比较函数。priority_queue< 阅读全文
posted @ 2012-08-21 21:52 琳&leen 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=3468代码:View Code 1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 __int64 s[400010]; 5 __int64 t[400010];//延迟数组,标记 6 void push(int w) 7 { 8 s[w]=s[w*2]+s[w*2+1]; 9 }10 void pushdown(int w, int d)11 {12 if(t[w])//如果延迟,向下更新13 {14 t[w*2]... 阅读全文
posted @ 2012-08-13 22:01 琳&leen 阅读(98) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1500View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<stdlib.h> 5 using namespace std; 6 struct node 7 { 8 int flag; 9 node *next[26];10 };11 int num;12 node *build()1 阅读全文
posted @ 2012-08-13 20:36 琳&leen 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1075View Code 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<stdlib.h> 5 using namespace std; 6 struct node 7 { 8 int flag; 9 char st[101]; 10 node *next[26]; 11 }; 12 node *build() 13 { 14 int i; 15 n... 阅读全文
posted @ 2012-08-13 20:34 琳&leen 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1247View Code 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 char str[50010][105]; 6 struct node 7 { 8 int flag; 9 node *next[26];10 };11 node *build()12 {13 int i;14 node *p;15 p=new node;16 ... 阅读全文
posted @ 2012-08-13 20:32 琳&leen 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 【转】01背包问题动态规划详解转载自sunstar1989最终编辑中华复生母动态规划是用空间换时间的一种方法的抽象。其关键是发现子问题和记录其结果。然后利用这些结果减轻运算量。比如01背包问题。因为背包最大容量M未知。所以,我们的程序要从1到M一个一个的试。比如,开始任选N件物品的一个。看对应M的背包,能不能放进去,如果能放进去,并且还有多的空间,则,多出来的空间里能放N-1物品中的最大价值。怎么能保证总选择是最大价值呢?看下表。测试数据:10,33,44,55,6c[i][j]数组保存了1,2,3号物品依次选择后的最大价值.这个最大价值是怎么得来的呢?从背包容量为0开始,1号物品先试,0,1 阅读全文
posted @ 2012-08-11 18:37 琳&leen 阅读(542) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<math.h> 4 #include<cstring> 5 #define INF 0x3f3f3f 6 struct node 7 { 8 double x,y,z,r; 9 }ht[105];10 double h[105][105];11 void prim(int n)12 {13 int vis[105];14 int pos,i,j;15 double min;16 double tr[105];17 memse. 阅读全文
posted @ 2012-08-11 17:10 琳&leen 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1003代码:View Code 1 #include<stdio.h> 2 int a[100010]; 3 int main() 4 { 5 int t,n,i,k; 6 int thissum,maxsum,xt,x,yt; 7 scanf("%d",&t); 8 for(k=1;k<=t;k++) 9 {10 scanf("%d",&n);11 for(i=0;i<n;i++)12 {13 ... 阅读全文
posted @ 2012-08-10 17:03 琳&leen 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1299代码:View Code 1 #include<stdio.h> 2 int main() 3 { 4 int n,i,j; 5 int a[1010],len[1010],max,maxlen=1; 6 scanf("%d",&n); 7 for(i=0;i<=9;i++) 8 len[i]=1; 9 for(i=0;i<n;i++)10 {11 scanf("%d.. 阅读全文
posted @ 2012-08-10 17:01 琳&leen 阅读(155) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 下一页