两道较为典型的单源最短路径问题,采用dijkstra解法 本来是四道练习题,后来发现后面两道用dijkstra来解的话总觉得有点冗余了,因此暂且分成三篇博客(本篇以及后两篇). ZOJ1053(POJ1122)-FDNY to the Rescue! //POJ1122-ZOJ1053 //dijkstra-需要记录路径 //给出n个路口的邻接矩阵,求给定多个火警到失火点的时间及任一路径 //注意输入最后一行时,cin.getline需要两次,猜测需要接受邻接矩阵最后一行其他字符后再接受下一行(…
两道有关欧拉回路的例题 POJ1300-Door Man //判定是否存在从某点到0点的欧拉回路 //Time:0Ms Memory:116K #include<iostream> #include<cstring> #include<cstdio> using namespace std; #define MAX 25 int st, n; int door[MAX]; int main() { char s[120]; while (scanf("%s&q…
Problem Given an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion? Code: class Solution { public: bool isPowerOfThree(int n) { if (n <= 0) return 0; int max_pow3 = log10(I…