上一页 1 ··· 56 57 58 59 60 61 62 63 64 ··· 182 下一页
摘要: floyd变形View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 306#define inf 0x3f3f3f3fint n, m, t;int map[maxn][maxn];void input(){ scanf("%d%d%d", &n, &m, &t); for (int i = 0; i < n; i++) f 阅读全文
posted @ 2012-07-04 10:51 undefined2024 阅读(178) 评论(0) 推荐(0)
摘要: 题意:给定一个矩阵,其中有一些地方有水,用一些长度任意,宽度为1的木板盖住这些有水的地方,问至少需要几块板子。分析:二分图最小点集覆盖。二分图建图方法如下,把每段连续的横向的水洼看成是一个X集合中的点,每段连续的纵向的水洼看成是Y集合中的点。矩阵每个有水单元看成是一个边,它连接了它所在的横向水洼在X集合中对应的点和它所在的纵向水洼在Y集合中对应的点。(对于一段连续的水洼,如果要铺木板,一定要铺得尽量长)这样最小点集覆盖的意义就变成了,矩阵中的每个有水的单元(二分图中的每条边)所在的横向和纵向的水洼(在X集合和Y集合中的两个端点)至少有一个被覆盖。求至少需要选几个点。View Code #inc 阅读全文
posted @ 2012-07-04 10:27 undefined2024 阅读(1136) 评论(2) 推荐(2)
摘要: 题意:约瑟夫问题变形,给定人数和最后存活的编号,问杀人间隔最少是多少。分析:从小到大枚举杀人间隔,然后用解约瑟夫问题的方法,求最后存活的人,如果恰好是要求的那个,则输出结果。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int n;int last(int n, int m){ int ret = 0; for (int i = 2; i <= n; i++) ret = (ret + 阅读全文
posted @ 2012-07-04 09:29 undefined2024 阅读(139) 评论(0) 推荐(0)
摘要: 题意:求凸包面积/50,并取整。分析:用模板。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxn 10005struct Point{ double x, y;} point[maxn], cvx[maxn];int n, m;bool mult(Point sp, Point ep, Point op){ return 阅读全文
posted @ 2012-07-03 19:20 undefined2024 阅读(249) 评论(0) 推荐(0)
摘要: 题意:约瑟夫问题分析:约瑟夫问题,有n个人站成一圈,依次编号0~n,编号为m%n的人出局,然后剩下的n-1个人重新编号,让原来在m后面的那个人编号为0,剩下的依次递增,编号从1~n-1。再次让编号为m%(n-1)的人出局。不断重复此过程,直至只剩一个人为止。问这个人在第一次编号时的编号。想要解决约瑟夫问题我们要逆推。试考虑刚才过程的逆过程。当前剩余x人且已编号,逆过程也就是把那个刚刚出局的人重新加进圈里来,并还原上一次的编号。我们需要做的是在当前x人中的编号为0的那个人前面插入一个人,让那个人的编号为m%(x+1),其余人的编号可根据这个新加进来的人的编号来确定。我们要从最后剩一个人的情况开始 阅读全文
posted @ 2012-07-03 16:44 undefined2024 阅读(363) 评论(0) 推荐(0)
上一页 1 ··· 56 57 58 59 60 61 62 63 64 ··· 182 下一页