B. Om Nom and Dark Park
在满二叉树上的某些边上添加一些值。使得根节点到叶子节点的路径上的权值和都相等。求最少需要添加多少。
我们利用性质解题。 考察兄弟节点。由于他们从跟节点到父节点这路径是相同的,所以需要添加的值为 2*max(lch,rch)-lch-rch; 同时将max(lch,rch)累加到父节点。
思路是最重要的。有时候不是聪不聪明的问题,而是会不会思考的问题。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const int INF=0x4fffffff;
const int EXP=1e-;
const int MS=; int num[<<MS]; int main()
{
int n;
memset(num,,sizeof(num));
scanf("%d",&n);
for(int i=;i<(<<(n+));i++)
scanf("%d",&num[i]);
int ans=;
for(int i=(<<n)-;i>;i--)
{
int lch=num[i<<];
int rch=num[i<<|];
int t=max(lch,rch);
num[i]+=t;
ans+=*t-lch-rch;
}
printf("%d\n",ans);
return ;
}
B. Om Nom and Dark Park的更多相关文章
- ZeptoLab Code Rush 2015 B. Om Nom and Dark Park DFS
B. Om Nom and Dark Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- ZeptoLab Code Rush 2015 B. Om Nom and Dark Park
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who l ...
- Zepto Code Rush 2014 B - Om Nom and Spiders
注意题目给的是一个nxm的park,设元素为aij,元素aij 有4种可能U(上移),D(下移),L(左移),R(右移) 假设第i行第j列元素aij(注意元素的索引是从0开始的) 当aij为D时,此时 ...
- CF Zepto Code Rush 2014 B. Om Nom and Spiders
Om Nom and Spiders time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Codefoces 436 B. Om Nom and Spiders
纯属练习JAVA.... B. Om Nom and Spiders time limit per test 3 seconds memory limit per test 256 megabytes ...
- C. Om Nom and Candies 巧妙优化枚举,将复杂度控制在10e6
C. Om Nom and Candies 无线超大背包问题 #include <iostream> #include <cstdio> #include <cstrin ...
- Codeforces 526D - Om Nom and Necklace 【KMP】
ZeptoLab Code Rush 2015 D. Om Nom and Necklace [题意] 给出一个字符串s,判断其各个前缀是否是 ABABA…ABA的形式(A和B都可以为空,且A有Q+1 ...
- Codeforces - ZeptoLab Code Rush 2015 - D. Om Nom and Necklace:字符串
D. Om Nom and Necklace time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces C - Om Nom and Candies
C - Om Nom and Candies 思路:贪心+思维(或者叫数学).假设最大值max(wr,wb)为wr,当c/wr小于√c时,可以枚举r糖的数量(从0到c/wr),更新答案,复杂度√c:否 ...
随机推荐
- cocos2dx实现功能强大的RichText控件
转自:http://blog.csdn.net/ljxfblog/article/details/26136773 最近准备做一个聊天系统,开始准备使用cocos2dx的UIRichText控件来显示 ...
- java提高数据库访问效率代码优化
package com.jb.jubmis.comm; import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQL ...
- OpenStack tokens id获取测试
- js逻辑与,或,非
[转,未整理] 1.逻辑非(!) 如果一个操作数是一个对象,返回true; 如果一个操作数是一个空字符串,返回false; 如果一个操作数是一个非空字符串,返回false; 如果一个操作数是一个数值0 ...
- Jquery 提示
1 文字提示: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...
- Codeforces Round #264 (Div. 2) C
题目: C. Gargari and Bishops time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- 从头学Android系列
从头学Android系列 http://blog.csdn.net/worker90/article/category/888358
- Circle-Progress-View
https://github.com/jakob-grabner/Circle-Progress-View
- 【JavaScript】JavaScript的Function与Object浅析
前言: JavaScript的面向对象是基于原形的,所有对象都有一条属于自己的原型链.Object与Function可能很多看Object instanceof Function , Function ...
- The sound of silence引发的关于互联网以及教育的利弊思考
“茫茫人海里,人群跟著人群,我们无时无刻不感到孤寂.停下来让我们好好沟通吧,否则人类的关系将日形恶化,沦为新世纪科技的牺牲品” ------- Simon 说实话,我第一次看<毕业生>应该 ...