两道有关欧拉回路的例题 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
两道较为典型的单源最短路径问题,采用dijkstra解法 本来是四道练习题,后来发现后面两道用dijkstra来解的话总觉得有点冗余了,因此暂且分成三篇博客(本篇以及后两篇). ZOJ1053(POJ1122)-FDNY to the Rescue! //POJ1122-ZOJ1053 //dijkstra-需要记录路径 //给出n个路口的邻接矩阵,求给定多个火警到失火点的时间及任一路径 //注意输入最后一行时,cin.getline需要两次,猜测需要接受邻接矩阵最后一行其他字符后再接受下一行(
1.POJ 1733 Parity game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5744 Accepted: 2233 Description Now and then you play the following game with your friend. Your friend writes down a sequence consisting of zeroes and ones. You cho
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2). DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ...,
两次DFS求树直径方法见 这里. 这里的直径是指最长链包含的节点个数,而上一题是指最长链的路径权值之和,注意区分. K <= R: ans = K − 1; K > R: ans = R − 1 + ( K − R ) ∗ 2; #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; ; struct n
Description A thief is running away! We can consider the city to N–. The tricky thief starts his escaping if and only if there is a street between cross u and cross v. Notice that he may not stay at the same cross in two consecutive moment. The cops