POJ 3437 Tree Grafting
题意:给出一个深度优先遍历树的up down顺序,求这棵树以及这棵树变为”左子右兄”树的高度
思路:直接dfs,x代表树1的高度,y代表树2的高度
- #include<cstdio>
- #include<cmath>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- int h1=,h2=,u=;
- char s[];
- int read(){
- char ch=getchar();int f=,t=;
- while (ch<''||ch>'') {if (ch=='-') f=-;ch=getchar();}
- while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
- return t*f;
- }
- void dfs(int x,int y){
- int son=;
- while (s[u]=='d'){
- u++;son++;
- dfs(x+,y+son);
- }
- u++;
- h1=std::max(h1,x);
- h2=std::max(h2,y);
- }
- int main(){
- int T=;
- scanf("%s",s);
- while (s[]!='#'){
- h1=h2=u=;
- dfs(,);
- printf("Tree %d: %d => %d\n",++T,h1,h2);
- scanf("%s",s);
- }
- }
POJ 3437 Tree Grafting的更多相关文章
- poj 3237 Tree [LCA] (树链剖分)
poj 3237 tree inline : 1. inline 定义的类的内联函数,函数的代码被放入符号表中,在使用时直接进行替换,(像宏一样展开),没有了调用的开销,效率也很高. 2. 很明显,类 ...
- poj 3237 Tree(树链拆分)
题目链接:poj 3237 Tree 题目大意:给定一棵树,三种操作: CHANGE i v:将i节点权值变为v NEGATE a b:将ab路径上全部节点的权值变为相反数 QUERY a b:查询a ...
- POJ 1741 Tree 求树上路径小于k的点对个数)
POJ 174 ...
- POJ 2378 Tree Cutting 3140 Contestants Division (简单树形dp)
POJ 2378 Tree Cutting:题意 求删除哪些单点后产生的森林中的每一棵树的大小都小于等于原树大小的一半 #include<cstdio> #include<cstri ...
- poj 1741 Tree(树的点分治)
poj 1741 Tree(树的点分治) 给出一个n个结点的树和一个整数k,问有多少个距离不超过k的点对. 首先对于一个树中的点对,要么经过根结点,要么不经过.所以我们可以把经过根节点的符合点对统计出 ...
- POJ 3723 Tree(树链剖分)
POJ 3237 Tree 题目链接 就多一个取负操作,所以线段树结点就把最大和最小值存下来,每次取负的时候,最大和最小值取负后.交换就可以 代码: #include <cstdio> # ...
- POJ 1741.Tree and 洛谷 P4178 Tree-树分治(点分治,容斥版) +二分 模板题-区间点对最短距离<=K的点对数量
POJ 1741. Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 34141 Accepted: 11420 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- poj 3237 Tree 树链剖分
题目链接:http://poj.org/problem?id=3237 You are given a tree with N nodes. The tree’s nodes are numbered ...
随机推荐
- typeof的用法
typeof可以返回变量的类型,返回值为字符串,其值有 "undefined" "boolean" "string" "numbe ...
- php中类的static变量使用
<?php #访问静态变量 #类外部: 类名::$类变量名 #类内部: 娄名::$类变量名或self::$类变量名 class Char{ public static $number = 0; ...
- Linux信号函数
1. signal函数: #include <signal.h> void (*signal(int signo, void (*func)(int)))(int); ret-成功返回信号 ...
- Lodash使用示例(比较全)
<html> <head> <meta name="viewport" content="width=device-width" ...
- 【bzoj3223】文艺平衡树
#include<bits/stdc++.h> #define N 300005 #define rat 4 using namespace std; struct Node{ int s ...
- 2015多校第6场 HDU 5355 Cake 贪心,暴力DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5355 题意:给你n个尺寸大小分别为1,2,3,…,n的蛋糕,要求你分成m份,要求每份中所有蛋糕的大小之 ...
- Name Disambiguation in AMiner-Clustering, Maintenance, and Human in the Loop
Name Disambiguation in AMiner: Clustering, Maintenance, and Human in the Loop paper:http://keg.cs.ts ...
- Hibernate检索策略与检索方式
hibernate的Session在加载Java对象时,一般都会把鱼这个对象相关联的其他Java对象也都加载到缓存中,以方便程序的调用.但很多情况下,我们不需要加载太多无用的对象到缓存中,一来会占用大 ...
- Word Search——经典题(还没细看)
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...
- [转载]Python命令行参数学习
转载自: http://blog.163.com/weak_time/blog/static/25852809120169333247925/ Python的命令行参数,提供了很多有用的功能,可以方便 ...