codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计
然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层
我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽量不用
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
const int N = 3e6;
const LL mod = 1e9+;
map<LL,LL>mp;
int get(LL x){
for(int i=;;++i){
LL tmp1=(1ll<<i);
LL tmp2=(1ll<<(i+))-;
if(x>=tmp1&&x<=tmp2)return i;
}
}
int main(){
int q;
scanf("%d",&q);
while(q--){
LL u,v,w;
int op;
scanf("%d%I64d%I64d",&op,&u,&v);
int curu=get(u),curv=get(v);
if(curu<curv){swap(u,v);swap(curu,curv);}
if(op==){
scanf("%I64d",&w);
while(curu>curv){
if(mp.find(u)==mp.end())mp[u]=w;
else mp[u]+=w;
u>>=;--curu;
}
while(u!=v){
if(mp.find(u)==mp.end())mp[u]=w;
else mp[u]+=w;
if(mp.find(v)==mp.end())mp[v]=w;
else mp[v]+=w;
u>>=;v>>=;
}
}
else{
w=;
while(curu>curv){
if(mp.find(u)!=mp.end())w+=mp[u];
--curu;u>>=;
}
while(u!=v){
if(mp.find(u)!=mp.end())w+=mp[u];
if(mp.find(v)!=mp.end())w+=mp[v];
u>>=;v>>=;
}
printf("%I64d\n",w);
}
}
return ;
}
codeforces 696A Lorenzo Von Matterhorn 水题的更多相关文章
- codeforces 696A A. Lorenzo Von Matterhorn(水题)
题目链接: A. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes inp ...
- 【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn
题目链接: http://codeforces.com/problemset/problem/696/A 题目大意: 一个满二叉树,深度无限,节点顺序编号,k的儿子是k+k和k+k+1,一开始树上的边 ...
- CodeForces 696A Lorenzo Von Matterhorn (LCA + map)
方法:求出最近公共祖先,使用map给他们计数,注意深度的求法. 代码如下: #include<iostream> #include<cstdio> #include<ma ...
- CodeForces 696A:Lorenzo Von Matterhorn(map的用法)
http://codeforces.com/contest/697/problem/C C. Lorenzo Von Matterhorn time limit per test 1 second m ...
- #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. ...
- Lorenzo Von Matterhorn
Lorenzo Von Matterhorn Barney lives in NYC. NYC has infinite number of intersections numbered with p ...
- C. Lorenzo Von Matterhorn LCA
C. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Lorenzo Von Matterhorn(STL_map的应用)
Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- SDUT1586 计算组合数(组合数)
这个题数据量小,不容易超时. #include<stdio.h> long long fac(int n) { ; ; i <= n ; i++) { m = i*m; } retu ...
- 分析windows宿主机Ping不通linux虚拟机的其中一种情况
ping不通的情况是由于设置网络选项的时候,可以看到界面名称的选择如下(当前选择的是无线网卡驱动):
- JS事件(事件冒泡和事件捕获)
事件流:描述的是在页面中接收事件的顺序 事件冒泡:由最具体的元素接收,然后逐级向上传播至最不具体的元素的节点(文档) 事件捕获:最不具体的节点先接收事件,而最具体的节点应该是最后接收事件 DOM中:用 ...
- java nio知识点总结
1.NIO是Java 4里面提供的新的API,目的是用来解决传统IO的问题.是用来解决传统io的问题的. 用来解决传统io的问题的.用来解决传统io的问题.阻塞的. 2.传统IO中,Stream是单向 ...
- PCA understanding
PCA understanding 我们希望获取玩具的位置,事实上我们只需要知道玩具在x轴的位置就可以了(但现实不知道).我们利用三个坐标轴,获取了2*3维度的数据,现实中我们如何通过分析六维度数据来 ...
- VB 语言学习笔记.
暂时用到,学习学习. 变量声明 Dim 变量名 as 数据类型类型 Set 实例 = new 类名 自定义数据类型 Type 数据类型标识符 域名 As 数据类型; 域名 As 数据类型; 域名 As ...
- TeeChart显示三维的图形,使用Surface
绘制一个球 根据公式x^2+y^2+z^2=R^2; 令x=RsinAcosB y=RcosAcosB z=RsinB using System; using System.Collections. ...
- 连续多行输入--C++ 中字符串标准输入的学习及实验(续篇)
编程中常常会用到连续多行输入的情况,如果事先知道要输入多少行的话,可以直接定义一个变量,然后用循环就可以实现了,但有时候事先并不知道,要输入多少行,于是就可以用到输入流碰到文件终止符的情况了,具体 ...
- ogre, dx, opengl坐标矩阵
opengl 右手坐标系 列向量 左乘 列主序存储矩阵osg 右手坐标系 行向量 右乘 行主序存储矩阵d3d 左手坐标系 行向量 右乘 行主序存储矩阵ogre 右手坐标系 列向量 ...
- POJ3485 区间问题
题目描述有些坑.. 题意: 有一条高速公路在x轴上,从(0,0)到(L,0).周围有一些村庄,希望能够在高速公路上开通几个出口,使得每个村庄到最近的出口距离小于D,求出最少需要开通多少个出口. 解题思 ...