摘要: 题目链接:http://poj.org/problem?id=3750 约瑟夫问题,直接模拟即可。 1 #include 2 #include 3 using namespace std; 4 5 const int maxn = 65; 6 7 int main() 8 { 9 char ch;10 int i, n, w, s, num[maxn];11 string per[maxn];12 while (scanf("%d", &n) != EOF)13 {14 for (i = 0; i > per[i]; // 保... 阅读全文
posted @ 2013-09-08 22:55 windysai 阅读(367) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://code.hdu.edu.cn/showproblem.php?pid=1233并查集的运用, 实质就是求最小生成树。先对所有的村庄距离从小到大排序,然后判断村庄之间是否属于同一集合,不是则将距离相加。属于同一集合,说明村庄连成了环,就不符合树的定义了。这样扫描下来,就求得最小生成树了。 要特别注意的是,数组越界问题。这个得益于Dwylkz的指点。由于村庄最多假设为100,为了防止边数越界,数组应该开到100 * 100 (10000)左右。 1 #include 2 #include 3 using namespace std; 4 5 const int ma... 阅读全文
posted @ 2013-09-08 12:00 windysai 阅读(175) 评论(0) 推荐(0) 编辑