A,给一棵完全二叉树,第一个操作,给两个点,两点路径上的所有边权值都增加w,第二个操作,给两个点,求两点路径上的所有边权值和。

我看一眼题就觉得是树链剖分,而我又不会树链剖分,扔掉。

后来查了题解,首先数据范围是1e18不可能是树剖,其次完全二叉树啊!不是普通的树啊!!sb。。。

//我做过此题,没做出来,被学弟教会。。虽然我做的题少,但我一向觉得至少自己做过的题都是记得的。。。但是。。。。

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
map<ll, ll> mp;
int main()
{
ll q, op, u, v, w, ans;
for (cin >> q; q--; ) {
cin >> op >> u >> v;
if (op == ) {
cin >> w;
while (u != v) {
if (u < v) swap(u, v);
mp[u] = mp[u] + w;
u /= ;
}
} else {
ans = ;
while (u != v) {
if (u < v) swap(u, v);
ans += mp[u];
u /= ;
}
cout << ans << endl;
}
}
return ;
}

B。树形dp,每一个兄弟结点在该节点的前面的概率肯定是0.5啊。我还想了好久。然后就水。

#include <vector>
#include <cstdio>
std::vector<int> tr[];
int sz[], n, tmp;
double ans[];
int dfs(int u) { for (int v: tr[u]) sz[u] += dfs(v); return ++sz[u]; }
void dfs(int u, double d) { ans[u] = d+; for (int v: tr[u]) dfs(v, (sz[u]--sz[v])/2.0+ans[u]); }
int main()
{
scanf("%d", &n);
for (int i = ; i <= n; ++i) scanf("%d", &tmp), tr[tmp].push_back(i);
dfs(); dfs(, );
for (int i = ; i <= n; ++i) printf("%f%c", ans[i], i==n?'\n':' ');
return ;
}

CodeForces 696A(Lorenzo Von Matterhorn ) & CodeForces 696B(Puzzles )的更多相关文章

  1. CodeForces 696A:Lorenzo Von Matterhorn(map的用法)

    http://codeforces.com/contest/697/problem/C C. Lorenzo Von Matterhorn time limit per test 1 second m ...

  2. codeforces 696A A. Lorenzo Von Matterhorn(水题)

    题目链接: A. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes inp ...

  3. 【CodeForces 697C】Lorenzo Von Matterhorn(LCA)

    Least Common Ancestors 节点范围是1~1e18,至多1000次询问. 只要不断让深的节点退一层(>>1)就能到达LCA. 用点来存边权,用map储存节点和父亲连边的权 ...

  4. #map+LCA# Codeforces Round #362 (Div. 2)-C. Lorenzo Von Matterhorn

    2018-03-16 http://codeforces.com/problemset/problem/697/C C. Lorenzo Von Matterhorn time limit per t ...

  5. CF 696 A Lorenzo Von Matterhorn(二叉树,map)

    原题链接:http://codeforces.com/contest/696/problem/A 原题描述: Lorenzo Von Matterhorn   Barney lives in NYC. ...

  6. C. Lorenzo Von Matterhorn LCA

    C. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input sta ...

  7. A. Lorenzo Von Matterhorn

    A. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input sta ...

  8. Lorenzo Von Matterhorn

    Lorenzo Von Matterhorn Barney lives in NYC. NYC has infinite number of intersections numbered with p ...

  9. Lorenzo Von Matterhorn(STL_map的应用)

    Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. Maven学习总结(四)——Maven核心概念

    一.Maven坐标 1.1.什么是坐标? 在平面几何中坐标(x,y)可以标识平面中唯一的一点. 1.2.Maven坐标主要组成 groupId:组织标识(包名) artifactId:项目名称 ver ...

  2. 使用程序获取整型数据和浮点型数据在内存中的表示---gyy整理

    使用程序获取整型数据和浮点型数据在内存中的表示. C++中整型(int).短整型(short int).单精度浮点数(float).双精度浮点数(double)在内存中所占字节数不同,因此取值范围也不 ...

  3. 解决git Push时请求username和password,而不是ssh-key验证

    转载自:https://blog.lowstz.org/posts/2011/11/23/why-git-push-require-username-password-github/ 之前开始用git ...

  4. How to install GSL on linux(ubuntu,centos,redhat)

    Test: ftp://ftp.gnu.org/gnu/gsl/gsl-1.15.tar.gz  success. ftp://ftp.gnu.org/gnu/gsl/gsl-1.13.0.tar.g ...

  5. java开发之IO流

    一直对IO流记不清楚,从别的地方转过来. 看下图: 流的概念和作用 学习Java IO,不得不提到的就是JavaIO流. 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象.即数据在两 ...

  6. Pyhon中的除法

    Python中分为3种除法:传统除法.精确除法.地板除. 传统除法: 如果是整数除法则执行地板除,如果是浮点数除法则执行精确除法. >>>1/2 0 >>>1.0/ ...

  7. chrome禁用某个网站js脚本的执行

      1 首先打开谷歌浏览器.如下 2 点击右上角,打开菜单进入[设置] 3 打开后,第一个界面是没有这个的,要滚动到最后点击[显示高级设置...] 4 展开第二页后,点击[隐私设置]->[内容设 ...

  8. left (outer) join , right (outer) join, full (outer) join, (inner) join, cross join 区别

    z       --     -- select   a.*,b.*   from   a   left   join   b   on   a.k   =   b.k      select   a ...

  9. Java [leetcode 14] Longest Common Prefix

    小二好久没有更新博客了,真是罪过,最近在看linux的东西导致进度耽搁了,所以今晚睡觉前怒刷一题! 问题描述: Write a function to find the longest common ...

  10. linux下socket keep alive讲解

    [需求] 不影响服务器处理的前提下,检测客户端程序是否被强制终了.[现状]服务器端和客户端的Socket都设定了keepalive属性.服务器端设定了探测次数等参数,客户端.服务器只是打开了keepa ...