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 ...
随机推荐
- Tiny6410 设备驱动之helloworld
在自己的工作目录下建立helloworld_driver.c #include <linux/init.h> #include <linux/module.h> //代码遵守的 ...
- Making your local server accessible from anywhere
In reality you probably don’t want to host you websites on your local computer unless you have a ver ...
- Nagios : Verifying Your Configuration
Every time you modify your configuration files, you should run a sanity check on them. It is importa ...
- socket选项自带的TCP异常断开检测
TCP异常断开是指在突然断电,直接拔网线等等情况下,如果通信双方没有进行数据发送通信等处理的时候,无法获知连接已经断开的情况. 在通常的情况下,为了使得socket通信不受操作系统的限制,需要自己在应 ...
- java Tomcat数据库连接池
1. 在tomcat服务器目录下面的conf中找到一个叫Context.xml的配置文件,在其中加入以下代码 <Resource name="jdbc/books" aut ...
- tomcat 设置默认编码格式
在tomcat目录下 conf文件夹下的server.xml中: <Connector port="80" protocol="HTTP/1.1" ...
- 【无聊放个模板系列】POJ 1274 (匈牙利)
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- Qt: 内建对话框(各种对话框都有了,且用到了qobject_cast解析sender的技术)
#include "BuiltinDialog.h" #include <QtGui/QTextEdit> #include <QtGui/QPushButton ...
- ArcGIS学习记录—KMZ KML与SHP文件互相转换
1.在google earth中绘制边界 工具栏中选择"Add Polygon".随意绘制一个多边形. 右击添加的图层名(左侧)保存位置为,选择保存为kmz或kml文件. ...
- Cinema 4D R16安装教程
CINEMA 4D_百度百科 http://baike.baidu.com/view/49453.htm?fr=aladdin 转自百度贴吧 [教程]Cinema 4D R16新功能介绍及安装教程_c ...