zoukankan      html  css  js  c++  java
  • 【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn

    题目链接:

      http://codeforces.com/problemset/problem/696/A

    题目大意:

      一个满二叉树,深度无限,节点顺序编号,k的儿子是k+k和k+k+1,一开始树上的边权都为0

      N(N<=1000)个操作,操作两种,1是从u到v的路径上的所有边权+w,2是求u到v的边权和。(1 ≤ v, u ≤ 1018, v ≠ u, 1 ≤ w ≤ 109)

    题目思路:

      【STL】【模拟】

      用map写很快,第一次用很生疏。现学只看了一点点。

      因为是满二叉树所以直接暴力求LCA和求解,把每条边全加上w,因为数很大 所以用map映射查找修改。

     1 //
     2 //by coolxxx
     3 ////<bits/stdc++.h>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<map>
     9 #include<memory.h>
    10 #include<time.h>
    11 #include<stdio.h>
    12 #include<stdlib.h>
    13 #include<string.h>
    14 //#include<stdbool.h>
    15 #include<math.h>
    16 #define min(a,b) ((a)<(b)?(a):(b))
    17 #define max(a,b) ((a)>(b)?(a):(b))
    18 #define abs(a) ((a)>0?(a):(-(a)))
    19 #define lowbit(a) (a&(-a))
    20 #define sqr(a) ((a)*(a))
    21 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    22 #define mem(a,b) memset(a,b,sizeof(a))
    23 #define eps (1e-8)
    24 #define J 10
    25 #define MAX 0x7f7f7f7f
    26 #define PI 3.14159265358979323
    27 #define N 1004
    28 using namespace std;
    29 typedef long long LL;
    30 int cas,cass;
    31 int n,m,lll,ans;
    32 map<LL,LL>t;
    33 int main()
    34 {
    35     #ifndef ONLINE_JUDGE
    36     freopen("1.txt","r",stdin);
    37 //    freopen("2.txt","w",stdout);
    38     #endif
    39     int i,j;
    40     LL x,y,z;
    41 //    for(scanf("%d",&cas);cas;cas--)
    42 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    43 //    while(~scanf("%s",s))
    44     while(~scanf("%d",&n))
    45     {
    46         for(i=1;i<=n;i++)
    47         {
    48             scanf("%d",&j);j--;
    49             if(!j)
    50             {
    51                 scanf("%I64d%I64d%I64d",&x,&y,&z);
    52                 while(x!=y)
    53                 {
    54                     if(x>y)
    55                         t[x]+=z,x>>=1;
    56                     else
    57                         t[y]+=z,y>>=1;
    58                 }
    59             }
    60             else
    61             {
    62                 scanf("%I64d%I64d",&x,&y);
    63                 z=0;
    64                 while(x!=y)
    65                 {
    66                     if(x>y)z+=t[x],x>>=1;
    67                     else z+=t[y],y>>=1;
    68                 }
    69                 printf("%I64d
    ",z);
    70             }
    71         }
    72     }
    73     return 0;
    74 }
    75 /*
    76 //
    77 
    78 //
    79 */
    View Code
  • 相关阅读:
    HttpWebRequest代理访问网站
    一段获得天气信息的.net代码
    C# 加密解密(DES,3DES,MD5,Base64) 类
    Windows 8 电话激活密钥。(更新至 20130721)
    微软官方的一段JavaScript判断.net环境
    我的第一篇。以后在这个记录我的点点滴滴。。。
    Linux 2.6内核中新的锁机制RCU
    再见,viewDidUnload方法
    Mechanical Sympathy
    Why should a selfimplemented getter retain and autorelease the returned object
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5774744.html
Copyright © 2011-2022 走看看