题目链接:http://codeforces.com/contest/931/problem/D

题目大意:给你一颗树,每个节点都会长苹果,然后每一秒钟,苹果往下滚一个。两个两个会抵消苹果。问最后在根节点能收到多少个苹果。

解题思路:昨天是我想复杂了,其实就是统计下每层的苹果数,若是奇数则答案+1。因为最终这些苹果都会滚落汇聚到根节点,所以在滚落过程中肯定会碰撞并相消无论苹果是怎么分布的。

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int N=1e5+; int dep_num[N];
vector<int>v[N]; void dfs(int u,int dep){
dep_num[dep]++;
for(int i=;i<v[u].size();i++){
int t=v[u][i];
dfs(t,dep+);
}
} int main(){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++){
int fa;
scanf("%d",&fa);
v[fa].push_back(i);
}
dfs(,);
int ans=;
for(int i=;i<N;i++){
ans+=dep_num[i]%;
}
printf("%d\n",ans);
return ;
}

Codeforces 931D Peculiar apple-tree(dfs+思维)的更多相关文章

  1. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  2. codeforces 812E Sagheer and Apple Tree(思维、nim博弈)

    codeforces 812E Sagheer and Apple Tree 题意 一棵带点权有根树,保证所有叶子节点到根的距离同奇偶. 每次可以选择一个点,把它的点权删除x,它的某个儿子的点权增加x ...

  3. poj 3321 Apple Tree dfs序+线段树

    Apple Tree Time Limit: 2000MS   Memory Limit: 65536K       Description There is an apple tree outsid ...

  4. [poj3321]Apple Tree(dfs序+树状数组)

    Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 26762   Accepted: 7947 Descr ...

  5. POJ3321 - Apple Tree DFS序 + 线段树或树状数组

    Apple Tree:http://poj.org/problem?id=3321 题意: 告诉你一棵树,每棵树开始每个点上都有一个苹果,有两种操作,一种是计算以x为根的树上有几个苹果,一种是转换x这 ...

  6. Codeforces 348B:Apple Tree(DFS+LCM+思维)

    http://codeforces.com/contest/348/problem/B 题意:给一棵树,每个叶子结点有w[i]个苹果,每个子树的苹果数量为该子树所有叶子结点苹果数量之和,要使得每个结点 ...

  7. POJ 3321 Apple Tree dfs+二叉索引树

    题目:http://poj.org/problem?id=3321 动态更新某个元素,并且求和,显然是二叉索引树,但是节点的标号不连续,二叉索引树必须是连续的,所以需要转化成连续的,多叉树的形状已经建 ...

  8. CodeForces 620E:New Year Tree(dfs序+线段树)

    E. New Year Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputout ...

  9. codeforces 916E Jamie and Tree dfs序列化+线段树+LCA

    E. Jamie and Tree time limit per test 2.5 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. 面试自我介绍之English

    Version 1 Hello, everyone. I am so glad to stand here. First of all, I will introduce myself. My nam ...

  2. Jenkins(四)---Jenkins添加密钥对

    一.添加密钥 1.添加git用户和git密码对 ,用于git客户端从gitlab上拉取代码到本地 /** lihaibo 文章内容都是根据自己工作情况实践得出. *版权声明:本博客欢迎转发,但请保留原 ...

  3. mac 必备工具

    iTerm 可以在一个窗口中垂直.水平分割窗口,而不用切换来切换去 一些基本功能如下: 1.分窗口操作:shift+command+d(横向)command+d(竖向) 2.查找和粘贴:command ...

  4. .gitignore 无效问题

    利用.gitignore过滤文件,如编译过程中的中间文件,等等,这些文件不需要被追踪管理. 现象: 在.gitignore添加file1文件,以过滤该文件,但是通过Git status查看仍显示fil ...

  5. NO.11天作业

    打印uid在30~40范围内的用户名.awk -F: '$3>=30 && $3<=40{print $1,$3}' /etc/passwd 打印第5-10行的行号和用户名 ...

  6. bzoj千题计划122:bzoj1034: [ZJOI2008]泡泡堂BNB

    http://www.lydsy.com/JudgeOnline/problem.php?id=1034 从小到大排序后 最大得分: 1.自己最小的>对方最小的,赢一场 2.自己最大的>对 ...

  7. [转载]Javascript 同步异步加载详解

    http://handyxuefeng.blog.163.com/blog/static/4545217220131125022640/ 本文总结一下浏览器在 javascript 的加载方式. 关键 ...

  8. [转载]内存的一些magic number和debug crt

    原文:http://www.360doc.com/content/13/0105/17/6295074_258392439.shtml 调试过debug版本的vc程序的人一定对0xCCCCCCCC和0 ...

  9. 20155331 2016-2017-2 《Java程序设计》第5周学习总结

    20155331 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 一.Java异常的基础知识 异常是程序中的一些错误,但并不是所有的错误都是异常,并且错误有时 ...

  10. hadoop启动步骤

    一.ssh的启动 ssh localhost二.hadoop的HDFS的格式化 bin/hadoop namenode -format三.hadoop的start-all.sh的启动 bin/tart ...