努力ing
你浪费的今天是昨天死去的人所渴望的明天!!!
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1856并查集的题目find()函数用到路径压缩,init()利用的是kruskal的思想#include<iostream>using namespace std;#define MAX 10000010struct node { int p; int r;};node f[MAX];int n,sum;void init(){ int i; for(i=0;i<MAX;i++) { f[i].p=i; f[i].r=1; }}int find(int x){ int t=f[x].p; i 阅读全文
posted @ 2013-05-29 21:24 努力ing 阅读(147) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1070#include<iostream>#include<string>#include<algorithm>#include<vector>using namespace std;struct node { string str; int m; int v; int day; double s;};double cmp(node& x,node& y){ if(x.s!=y.s) return x.s<y.s; else return 阅读全文
posted @ 2013-05-27 17:37 努力ing 阅读(154) 评论(0) 推荐(0)
摘要: bfs 的题目http://acm.hdu.edu.cn/showproblem.php?pid=1372题目简述:一个8*8的棋盘,输入两点,求马从第一点到第二点所需要的最少步数Inpute2e4a1b2b2c3OutputTogetfrome2toe4takes2knightmoves.Togetfroma1tob2takes4knightmoves.Togetfromb2toc3takes2knightmoves.代码:#include<iostream>#include<queue>using namespace std;int map[10][10];int 阅读全文
posted @ 2013-05-27 09:01 努力ing 阅读(139) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1506第一种方法:#include<stdio.h>int a[100005];int right[100005];int left[100005];int main(){ int n; int i; __int64 max; while(scanf("%d",&n)!=EOF&&n) { for(i=0;i<n;i++){ scanf("%d",&a[i]); left[i]=right[i]=i; } for(i=0 阅读全文
posted @ 2013-05-26 10:13 努力ing 阅读(121) 评论(0) 推荐(0)
摘要: 简单dphttp://acm.hdu.edu.cn/showproblem.php?pid=1864#include<iostream>#include<string>using namespace std;double dp[50];double max(double a,double b){ return a>b?a:b;}int main(){ int m,n,j,i; double val,A,B,C; char c; double v; double sum[30]; int flag; while(cin>>val>>n& 阅读全文
posted @ 2013-05-25 14:29 努力ing 阅读(128) 评论(0) 推荐(0)
摘要: 记忆搜索http://acm.hdu.edu.cn/showproblem.php?pid=1978题目简述:机器人从第一个点出发到达最后一点,有多少种方法,结果%10000;Input166456643223172114627584395766215311372Output3948第一种方法:#include<iostream>using namespace std;int n,m;int map[205][205];int dp[205][205];int min(int a,int b){ return a<b?a:b;}int bfs(int x,int y,int 阅读全文
posted @ 2013-05-23 15:46 努力ing 阅读(160) 评论(0) 推荐(0)
摘要: //prim算法主要用来计算带权值的最小连通图#define INF 999999999int c[105][105]; //定义一个图的矩阵int flag[105]; //定义一个标记数组,初始化为0,如果已经连通,就标志为1int prim[105]; //定义一个数组,用来存放每一步的最小值int n,m; //n表示图有n个节点,有m条边int sum; //sum表示最小连通的权值和void Prim(){ int i,j; for(i=1;i<=n;i++) { prim[i]=... 阅读全文
posted @ 2013-05-20 09:40 努力ing 阅读(194) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1242用bfs做,要用优先队列#include<iostream>#include<string>#include<queue>using namespace std;int sx,sy,ex,ey;int n,m;int map[205][205];int dis[4][2]={0,1,1,0,0,-1,-1,0};struct node{ int x,y; int step; friend bool operator<(node a,node b) //优先队列必 阅读全文
posted @ 2013-05-19 22:09 努力ing 阅读(222) 评论(0) 推荐(0)
摘要: 广搜的题目http://acm.hdu.edu.cn/showproblem.php?pid=1253用优先队列会超时时间少,空间大#include<iostream>#include<queue>using namespace std;int a,b,c,t;int map[55][55][55];int dir1[2]={1,-1};int dir2[4][2]={{1,0},{0,1},{-1,0},{0,-1}};struct node{ int x,y,z; int time;};bool cmp(int v,int w,int u){ if(v<0|| 阅读全文
posted @ 2013-05-19 22:02 努力ing 阅读(128) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1081矩阵压缩的题目#include<iostream>using namespace std;int find(int a[],int n) //找最大子序列{ int max=-10004; int i,sum=0; for(i=0;i<n;i++) { sum+=a[i]; if(sum>max) max=sum; if(sum<0) sum=0; } return max;}int main(){ int i,j,k,n; int a[150][150]; while(c 阅读全文
posted @ 2013-05-19 21:58 努力ing 阅读(125) 评论(0) 推荐(0)