摘要: 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 struct Time 5 { 6 int hour; 7 int minute; 8 int angle; 9 };10 double compute_angle(Time a)11 {12 if (a.hour >= 12)13 a.hour -= 12;14 int t = abs(a.hour*60 + a.minute - a.minute*12); //乘以2避免浮点数运算15... 阅读全文
posted @ 2013-04-06 17:43 PegasusWang 阅读(494) 评论(0) 推荐(0)
摘要: 以下是基于图的链表表示的:dfs和bfs的演示:http://sjjg.js.zwu.edu.cn/SFXX/sf1/gdyxbl.html (深搜)http://sjjg.js.zwu.edu.cn/SFXX/sf1/sdyxbl.html (广搜)bfs通过检测边发现点,被发现点(但未探索)入队。(被探索是指是否检测过与该点相关联的临近顶点)一个顶点被完全探索当且仅当他的所有边被检测。一个顶点探索完选另一个顶点,被选点应位于被发现但未被探索点队列的队首。待探索点集为空时算法结束。(bfs探索顺序与发现顺序一致,dfs发现后马上探索) 1 #include <iostream> 阅读全文
posted @ 2013-04-06 15:55 PegasusWang 阅读(25193) 评论(2) 推荐(1)
摘要: 题目链接http://acm.timus.ru/problem.aspx?space=1&num=1033唯一注意的就是当图不连通时两个角都要搜索,搜索的总和才是最终答案。#include <iostream>#include <cstdio>#include <cstring>int n, num;char map[34][34];bool visited[34][34] = {0};int dir[4][2] = {{-1,0}, {0,1}, {1,0}, {0,-1}};void dfs(int x, int y){ if ((x==0 &a 阅读全文
posted @ 2013-04-06 14:28 PegasusWang 阅读(374) 评论(0) 推荐(0)
摘要: 1 #include <iostream> 2 #include <cstdio> 3 char map[21][21]; 4 int H, W, starti, startj, num; //H行 W列 5 int dir[4][2] = {{-1,0}, {0,1}, {1,0}, {0,-1}}; 6 void dfs(int x, int y) 7 { 8 ++num; 9 for (int i = 0; i < 4; ++i)10 {11 int fx = x + dir[i][0];12 ... 阅读全文
posted @ 2013-04-06 12:46 PegasusWang 阅读(340) 评论(0) 推荐(0)