codeforces 696A Lorenzo Von Matterhorn 水题
2016-07-15 21:52
369 查看
这题一眼看就是水题,map随便计
然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层
我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽量不用
View Code
然后我之所以发这个题解,是因为我用了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+7; map<LL,LL>mp; int get(LL x){ for(int i=0;;++i){ LL tmp1=(1ll<<i); LL tmp2=(1ll<<(i+1))-1; 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==1){ scanf("%I64d",&w); while(curu>curv){ if(mp.find(u)==mp.end())mp[u]=w; else mp[u]+=w; u>>=1;--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>>=1;v>>=1; } } else{ w=0; while(curu>curv){ if(mp.find(u)!=mp.end())w+=mp[u]; --curu;u>>=1; } while(u!=v){ if(mp.find(u)!=mp.end())w+=mp[u]; if(mp.find(v)!=mp.end())w+=mp[v]; u>>=1;v>>=1; } printf("%I64d\n",w); } } return 0; }
View Code
相关文章推荐
- 随机跳转
- 唯有一款软件,能用盗版的我坚决不用正版
- RxJava学习笔记
- Intent 显示与隐式
- cf 697 A
- C++遍历文件
- JQuery trigger 个人理解手记
- 什么是对象关系映射ORM?
- Android的活动周期
- uglifyjs压缩JS的
- C++捕获cin输入错误类型值的问题
- XCode 7 iOS 9 app submission failed.
- overflow:hidden
- hash_map原理
- JS面试题-动态生成表格代码
- C++中Mat类型与CSV、xml文件的存取转换
- 使用Maven运行Java main的3种方式
- mysql的两阶段提交协议
- angularJs+MVC+C#学习(二)
- cf 697 B(模拟)