08 2012 档案
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2371View Code 1 #include <iostream> 2 #include<cstdio> 3 using namespace std; 4 long int a[1005][1005]; 5 int main() 6 { 7 int n,flag,i,j; 8 while(~scanf("%d",&n)) 9 {10 if(n==0)11 break;12 fo...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2427View Code 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <cstdio> 5 #define MAX 20001 6 using namespace std; 7 8 struct node 9 { 10 int li; 11 int num; 12 }st[MAX*4];/
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2430题意:大概是有n个柱子,每个的长度是1到h[i]任意一个整数,用一根绳子把这些柱子的顶端都连起来,使得绳子长度最长。View Code 1 #include <iostream> 2 #include<math.h> 3 #include<cstdio> 4 #include<cstring> 5 using namespace std; 6 int main() 7 { 8 double
阅读全文
摘要:题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2420代码:View Code 1 #include<stdio.h> 2 struct node 3 { 4 int x; 5 int l1;//记录i点左面1的数目 6 int l2;//记录i点左面2的数目 7 }a[30010]; 8 int main() 9 {10 int i,n,max,sum;11 scanf("%d",&n);12 a[0].l1=0;13 a[0].l2...
阅读全文
摘要:题目: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
阅读全文
摘要:转自: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<
阅读全文
摘要:题目: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]...
阅读全文
摘要:题目: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
阅读全文
摘要:题目: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...
阅读全文
摘要:题目: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 ...
阅读全文
摘要:【转】01背包问题动态规划详解转载自sunstar1989最终编辑中华复生母动态规划是用空间换时间的一种方法的抽象。其关键是发现子问题和记录其结果。然后利用这些结果减轻运算量。比如01背包问题。因为背包最大容量M未知。所以,我们的程序要从1到M一个一个的试。比如,开始任选N件物品的一个。看对应M的背包,能不能放进去,如果能放进去,并且还有多的空间,则,多出来的空间里能放N-1物品中的最大价值。怎么能保证总选择是最大价值呢?看下表。测试数据:10,33,44,55,6c[i][j]数组保存了1,2,3号物品依次选择后的最大价值.这个最大价值是怎么得来的呢?从背包容量为0开始,1号物品先试,0,1
阅读全文
摘要: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.
阅读全文
摘要:题目: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 ...
阅读全文
摘要:题目: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..
阅读全文
摘要:题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2080代码:View Code 1 #include<stdio.h> 2 #include<string.h> 3 int max(int a, int b) 4 { 5 if(a>b) 6 return a; 7 else 8 return b; 9 }10 int main()11 {12 int len1,len2,i,j;13 char str1[505],str2[505];14 ...
阅读全文
摘要:题目 :http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1730代码:View Code #include<stdio.h>int main(){ int n,i,j,dp[105][105]; scanf("%d",&n); for(i=0;i<n;i++) for(j=0;j<=i;j++) scanf("%d",&dp[i][j]); for(i=n-2;i>=0;i--) { for(j=0;j<
阅读全文
摘要:最大子序列和问题问题描述:输入一组整数,求出这组数字子序列和中最大值。也就是只要求出最大子序列的和,不必求出最大的那个序列。例如:序列:-2 11 -413 -5 -2,则最大子序列和为20。序列:-6 2 4 -7 5 3 2 -1 6 -9 10 -2,则最大子序列和为16。算法一://穷举法,复杂度O(n^3)long maxSubSum1(const vector<int>& a){ long maxSum = 0; for (int i = 0; i < a.size(); i++) { for (int j = i; j < a.size(); j+
阅读全文
摘要:产生冠军Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4952Accepted Submission(s): 2364Problem Description有一群人,打乒乓球比赛,两两捉对撕杀,每两个人之间最多打一场比赛。球赛的规则如下:如果A打败了B,B又打败了C,而A与C之间没有进行过比赛,那么就认定,A一定能打败C。如果A打败了B,B又打败了C,而且,C又打败了A,那么A、B、C三者都不可能成为冠军。根据这个规则,无需循环较量,或许就能
阅读全文
摘要:确定比赛名次Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5871Accepted Submission(s): 2190Problem Description有N个比赛队(1<=N<=500),编号依次为1,2,3,。。。。,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道每场比赛的结果,即P1赢P2,用P1,P2表示,排名时P1在P2之前。现在请你编程序确
阅读全文