摘要: 题目大意是找到一个最多的老鼠序列,使得序列中的老鼠的体重满足递增,相应老鼠的速度满足递减。思路就是先按体重递增进行sort排序,然后按照体重找到最长递减子序列即可,用动态规划做比较简单。状态f[i]表示前i个老鼠中的最长递减子序列长度,状态转移方程为f[i] = max{f[j], mice[j].speed > mice[i].speed} + 1, 最后找出最大的f[i]即可。注意此题还需要输出找到的序列中的老鼠的最原始的标号,因此不仅要在刚开始的时候把每个老鼠的最初的序号记下来,还要在进行状态转移的时候把当前的老鼠的位置标记下来。AC code: 1 #include <io 阅读全文
posted @ 2012-03-01 21:10 背着超人飞 阅读(340) 评论(0) 推荐(0)
摘要: 题目大意就是找到所有可能被传染的人数,题意挺容易理解的。很容易联想到用并查集去做,将每组除第一个人之外都加到第一个人所在的集合,这样输出与0在一个集合的元素个数就是所求。AC code: 1 #include <iostream> 2 #define MAX 30001 3 using namespace std; 4 int father[MAX], num[MAX]; 5 int n, m; 6 7 void ini(int n) 8 { 9 for(int i = 0; i < n; i++)10 {11 father[i] = i;12 ... 阅读全文
posted @ 2012-02-28 21:16 背着超人飞 阅读(143) 评论(0) 推荐(0)
摘要: 题目大意是判断两台电脑是否连通 ,大致思路是利用并查集,将可以直接通信并且完好的电脑划到同一集合中,通过判断两台电脑是否在同一集合就可以知道两台电脑是否可以连通,需要注意的是,必须保证可以通信的每对计算机是完好无损的。AC code: 1 #include <iostream> 2 #define MAX 1005 3 using namespace std; 4 int map[MAX][MAX]; 5 int f[MAX]; 6 int mul(int x)//求平方的函数 7 { 8 return x * x; 9 }10 int find(int x)//并查集11 {12 阅读全文
posted @ 2012-02-28 13:00 背着超人飞 阅读(151) 评论(0) 推荐(0)
摘要: 题目大意是找出一个人作为源点,使得从这个人开始散播信息到全部人都得到信息所用时间最少,输出这个人的号码跟最少时间。算是一道典型的最短路的题目,用floyd算法即可解决。AC code: 1 #include <iostream> 2 #define MAX 101 3 #define INF 1000000 4 using namespace std; 5 int dist[MAX][MAX]; 6 int map[MAX][MAX]; 7 int n; 8 int contact; 9 void input()10 {11 int i, j;12 int id, time;1.. 阅读全文
posted @ 2012-02-27 23:30 背着超人飞 阅读(161) 评论(0) 推荐(0)
摘要: 这一题跟POJ的heavy transportation 一题正好相反,是求最短路中的边权最长边。用的dijsktra算法,用邻接表存储各边权。AC code: 1 #include <iostream> 2 #include <cmath> 3 #include <string.h> 4 #define MAX 1000 5 #define MAXN 100000 6 using namespace std; 7 8 int tmap[MAX][2]; 9 float map[MAX][MAX];10 float dis[MAX];11 bool vis[ 阅读全文
posted @ 2012-02-27 21:10 背着超人飞 阅读(175) 评论(0) 推荐(0)
摘要: 这一题算是最短路的变型,要求的是从起点到终点的所有路中最小的一段最大,即求一条最长路,输出这条路中的最小值。我是用Dijstra算法做的。AC code: 1 #include <iostream> 2 #define MAX 2000 3 using namespace std; 4 int map[MAX][MAX]; 5 bool vis[MAX]; 6 int dis[MAX];//存放从起点到第i点的最长路中的最短边长度 7 int num;//记录方案数 8 int n, m; 9 10 void Dij()11 {12 int max;13 int v = 0;1.. 阅读全文
posted @ 2012-02-25 23:26 背着超人飞 阅读(147) 评论(0) 推荐(0)
摘要: 题目大意是找到一条生成树,使得该树中最大的一条边在所有树中的最大边最小。算是最小生成树的一道变型。由于边数可能比较多,所以用prim算法比较合适。AC code: 1 #include <iostream> 2 #include <string.h> 3 #define MAX 1000 4 using namespace std; 5 6 int n, map[MAX][MAX]; 7 bool vis[MAX]; 8 int dis[MAX]; 9 int ans;10 11 void ini()12 {13 int i, j;14 for(i = 0; i < 阅读全文
posted @ 2012-02-24 16:50 背着超人飞 阅读(132) 评论(0) 推荐(0)
摘要: 这一题是比较裸的最小生成树的题,用邻接表记录数据。我是用kruscal算法做的,思路比较简单,中间用并查集判断是否产生回路。AC code: 1 #include <iostream> 2 #include <stdlib.h> 3 #include <algorithm> 4 #define MAX 200 5 #define MAXN 10000 6 using namespace std; 7 8 struct line{ 9 int start, end, len;10 };11 12 struct line lines[MAXN];13 int m 阅读全文
posted @ 2012-02-24 14:22 背着超人飞 阅读(113) 评论(0) 推荐(0)
摘要: 这一题算是比较裸的最小生成树的题,用kruscal很好做,再加上并查集优化就没问题了。AC code: 1 #include <iostream> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <algorithm> 5 using namespace std; 6 struct Line{ 7 int start; int end; int lenth; 8 }line[1000]; 9 int n, linenumber, minlenth;10 int father[1000] 阅读全文
posted @ 2012-02-24 14:11 背着超人飞 阅读(138) 评论(0) 推荐(0)
摘要: 这题算是比较简单的广搜题,每次有三种决策,可添加一些剪枝加快速度,直接看代码吧: 1 #include <iostream> 2 #define MAX 200001 3 using namespace std; 4 int n, k; 5 bool vis[MAX];//记录某点是否被走过 6 int queue[MAX], time[MAX]; 7 int bfs() 8 { 9 int front = 0, rear = 1;10 int x, temp;11 queue[front] = n; vis[n] = true;//把起点放入队列的头部12 w... 阅读全文
posted @ 2012-02-24 10:55 背着超人飞 阅读(151) 评论(0) 推荐(0)