CodeForces 696A(Lorenzo Von Matterhorn ) & CodeForces 696B(Puzzles )
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 )的更多相关文章
- CodeForces 696A:Lorenzo Von Matterhorn(map的用法)
http://codeforces.com/contest/697/problem/C C. Lorenzo Von Matterhorn time limit per test 1 second m ...
- codeforces 696A A. Lorenzo Von Matterhorn(水题)
题目链接: A. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes inp ...
- 【CodeForces 697C】Lorenzo Von Matterhorn(LCA)
Least Common Ancestors 节点范围是1~1e18,至多1000次询问. 只要不断让深的节点退一层(>>1)就能到达LCA. 用点来存边权,用map储存节点和父亲连边的权 ...
- #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 ...
- CF 696 A Lorenzo Von Matterhorn(二叉树,map)
原题链接:http://codeforces.com/contest/696/problem/A 原题描述: Lorenzo Von Matterhorn Barney lives in NYC. ...
- C. Lorenzo Von Matterhorn LCA
C. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input sta ...
- A. Lorenzo Von Matterhorn
A. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Lorenzo Von Matterhorn
Lorenzo Von Matterhorn Barney lives in NYC. NYC has infinite number of intersections numbered with p ...
- Lorenzo Von Matterhorn(STL_map的应用)
Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- 【leetcode】Container With Most Water(middle)
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- hdu 2516 取石子游戏 博弈论
很显然的nim游戏的变形,很好找规律 先手败:2,3,5,8,13…… 其他先手胜.即满足菲波拉数列. 代码如下: #include<iostream> #include<stdio ...
- MySQL在windows和linux下的表名大小写问题
MySQL在windows下是不区分大小写的,将script文件导入MySQL后表名也会自动转化为小写,结果再想要将数据库导出放到linux服务 器中使用时就出错了.因为在linux下表名区分大小写而 ...
- 多线程 (五)NSOperation
NSOperation是对GCD的分装,OC语言,更简单方便 NSOperation和NSOperationQueue一起使用也能实现多线程编程 基本步骤: 将操作封装到一个NSOperation对象 ...
- ASC #1
开始套题训练,第一套ASC题目,记住不放过每一题,多独立思考. Problem A ZOJ 2313 Chinese Girls' Amusement 循环节 题意:给定n,为圆环长度,求k < ...
- 重载操作符 operator overloading 学习笔记
重载操作符,只是另外一种调用函数的方法和表现方式,在某些情况它可以让代码更简单易读.注意不要过度使用重载操作符,除非它让你的类更简单,让你的代码更易读. 1语法 如下: 其中友元,关键字不是必须的,但 ...
- 排查Java线上服务故障的方法和实例分析
前言 作为在线系统负责人或者是一个技术专家,你可能刚刚接手一个项目就需要处理紧急故障,或者被要求帮忙处理一些紧急的故障,这个时候的情景是: (1)你可能对这个业务仅仅是听说过,而不怎么真正了解: (2 ...
- 将OutLook.exe注册为服务,让其一直保持开启状态
类似于TaobaoProtect.exe是由TBSecSvc服务启动的 http://stackoverflow.com/questions/3582108/create-windows-servic ...
- Smallest unused ID
http://www.codewars.com/kata/smallest-unused-id Description: Hey awesome programmer! You've got much ...
- 函数buf_LRU_search_and_free_block
/******************************************************************//** Try to free a replaceable bl ...