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 ...
随机推荐
- html5移动web开发实战必读书记
原文 http://itindex.net/detail/50689-html5-移动-web 主题 HTML5 一.配置移动开发环境 1.各种仿真器.模拟器的下载安装 http://www.mob ...
- 想让安卓 APP 如丝般顺滑?
随着安卓手机市场占有率的节节攀升,随便在大街上找几个人估计 80% 用的都是安卓手机吧!用安卓手机的人这么多,不知道大家是否曾经感觉到过 APP 卡顿.死机?是否遇到应用程序无响应.闪退?本文就为大家 ...
- 可以继承的C++ Singleton基类
单例模式(Singleton Pattern)是设计模式中的一种,它用来保证系统中最多只能存在一个它的实例,其做法是由类自身来创建和持有它的对象实例,把对实例的创建权和管理权都控制在自己手中,以便控制 ...
- 获取Android系统时间
目的: 输入 2014-09-09 14:02:03 输出 等待:1小时20分 注意: HH:mm:ss 为获取手机 24小时格式的时间 15:03 hh:mm:ss 为12小时模式的时 ...
- 不要在头文件中使用 using namespace std;
不要在头文件中使用(using namespace std;). 若你使用了using namespace std;,在某一头文件中,那么包含这些头文件的文件就失去了"namespace ...
- 锋利的JQuery-认识Jquery
今天开始学习菜鸟的JQuery,这本书在一前看过一遍了,但是由于虽然看了,但是将近一年在工作中基本上没有用上,很是悲催,菜鸟想,用一到两个星期时间把这本书看一遍吧.就像菜鸟前面的jsdom一样,菜鸟写 ...
- JQuery设置与获取RadioButtonList和CheckBoxList的值
有这样一个问题,要获取ASP.NET控件RadioButtonList的值,首先想到的就是$("#<%=RadioButtonList1.ClientID %>").v ...
- [POJ 2356] Find a multiple
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6535 Accepted: 2849 ...
- [2015编程之美] 第一场C
题目3 : 质数相关 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 两个数a和 b (a<b)被称为质数相关,是指a × p = b,这里p是一个质数.一个集合S被 ...
- Tomcat配置HTTPS方式
简要记录主要步骤备忘 1.进入到jdk下的bin目录 2.输入如下指令 keytool -v -genkey -alias tomcat -keyalg RSA -keystore d:/tomcat ...