POJ 2568/ZOJ 1965 Decode the Tree】的更多相关文章

题意:在树中,每次删去节点值最小的叶子结点. 每删去一个点,就给出与这相连的点的值,直到最后只剩下一个根结点,给这N-1个数,重新建立这个树. 思路: 给出的节点号按次序存入到数组a中,将未给出的数存入到rest数组中去,并从小到大排序. 每次取一个给出的节点,那么我们需要求出与该点相连的被删去的点v. 而点v必定为 “不会在之后的数据中出现的值(即之后删除的叶子节点中再也没有与之相连的,即改点为叶子节点)” 和 “当前rest数组中最小的值”  中的最小值. 那么只要预处理一下,对于给出的节点…
Description A Sudoku grid is a 16x16 grid of cells grouped in sixteen 4x4 squares, where some cells are filled with letters from A to P (the first 16 capital letters of the English alphabet), as shown in figure 1a. The game is to fill all the empty g…
题目链接 题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket . 思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接变为*,这样可以避免重复搜索. //POJ 1562 ZOJ 1709 #include <stdio.h> #include <string.h> #include <iostream> #include <stack> #include <algori…
题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> ; const int INF = 0x3f3f3f3f; double x[MAXN], y[MAXN]; int n; double sum(double x1, double y1) { ; ; i<=n; +…
水题三题: 1.给你B和N,求个整数A使得A^n最接近B 2. 输出第N个能被3或者5整除的数 3.给你整数n和k,让你求组合数c(n,k) 1.poj 3100 (zoj 2818) Root of the Problem: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2818 http://poj.org/problem?id=3100 #include<cstdio> #include<cmath>…
题目大意:2567是给出一棵树,让你求出它的Prufer序列.2568时给出一个Prufer序列,求出这个树. 思路:首先要知道Prufer序列.对于随意一个无根树,每次去掉一个编号最小的叶子节点,并保存这个节点所连接的节点所得到的序列就是这棵树的Prufer序列. 这个序列有十分优雅的性质.它能与无根树一一相应.因此.两个标号一样的无根树得到的Prufer序列也一定是一样的. 此外,设一个节点的度数是d[i],那么他会在Prufer序列中出现d[i] - 1次. 2567:记录每个节点的度.依…
ZOJ :: Problems :: Show Problem 1436 -- Horizontally Visible Segments 用线段树记录表面能被看见的线段的编号,然后覆盖的时候同时把能看到的线段记录下来.这里要用到拆点,在两个整点之间插入一个点. 最后O(n^2)统计三角形的个数,因为每条线段可以看见的另外的线段的条数不多,所以可以直接枚举两条边. 代码如下: #include <cstdio> #include <iostream> #include <al…
A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each node has a boolean (0 or 1) labeled on it. Initially, all the labels are 0. We define this kind of operation: given a subtree, negate all its labels. An…
A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4058   Accepted: 2005 Description Luke wants to upgrade his home computer network from 10mbs to 100mbs. His existing network uses 10base2 (coaxial) cables that allow you…
http://poj.org/problem?id=1080 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=27 /* zoj 1027 poj 1080 思路: 三种状态,取最大值: s1[i]和s2[j]配 :dp[i-1][j-1]+cost[my[s1[i]]][my[s2[j]]]; s1[i]和'-' 配: dp[i-1][j]+cost[my[s1[i]]][my['-']]; s2[j]和'-' 配: dp[…