zoukankan      html  css  js  c++  java
  • 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+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
    ",w);  
        }
      }
      return 0;
    }
    View Code
  • 相关阅读:
    在jenkins和sonar中集成jacoco(一)--使用jacoco收集单元测试的覆盖率
    持续集成一天一美元
    在jenkins和sonar中集成jacoco(二)--在jenkins中生成jacoco覆盖率报告
    day02--课后练习
    python之路-day02
    day01--课后练习
    python之路-day01
    python-FTP程序
    python-选课系统
    python- ATM与购物商城
  • 原文地址:https://www.cnblogs.com/shuguangzw/p/5674869.html
Copyright © 2011-2022 走看看