摘要: 题目:有n个人,其中一个明星和n-1个群众,群众都认识明星,明星不认识任何群众,群众两两间可能认识也可能不认识,每次问一个人是否认识另外一个人的代价为0(1),试设计一种算法找出明星,并给出时间复杂度。答案:群众都认识明星,明星不认识任何群众。设其中任意2个人A,B,询问A是否认识B。若是,则A不是明星,排除之,否则B不是明星。每次询问都可以排除一人,因此最多询问n-1次,时间复杂度O(n)。 阅读全文
posted @ 2013-09-17 20:01 l851654152 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 分段K-M-P 只需要记录上一段已经匹配了的长度,再接着从匹配下一段就可以了。 阅读全文
posted @ 2013-09-17 19:35 l851654152 阅读(178) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #include #include #include using namespace std;struct foo{ char d;};struct s{ int x:3;int y:4;int z:5;double a;};#include void main(){ int N; cin >> N; float x= 1.0; float x0; float f; float f1; do { x0 = x; f = x0 * x0 - N; f1 = 2 * x0; x = x0- f/f1; } while (fabs(x 阅读全文
posted @ 2013-09-17 15:24 l851654152 阅读(204) 评论(0) 推荐(0) 编辑