当前位置: 首页>>代码示例>>C++>>正文


C++ IntervalTree::init方法代码示例

本文整理汇总了C++中IntervalTree::init方法的典型用法代码示例。如果您正苦于以下问题:C++ IntervalTree::init方法的具体用法?C++ IntervalTree::init怎么用?C++ IntervalTree::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IntervalTree的用法示例。


在下文中一共展示了IntervalTree::init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(){
  int T; scanf("%d", &T);
  while (T--){
    scanf("%d", &N);
    for (int i = 0; i < N; i++) scanf("%d %d", &x[i], &y[i]);

    ds.init();
    citysTree.init();
    stateTree.init();

    int M; scanf("%d", &M);
    while (M--){
      char cmd[32]; scanf("%s", cmd);
      if (!strcmp(cmd, "road")){
        int A, B; scanf("%d%d", &A, &B);
        int pA = ds.find(A), pB = ds.find(B);
        if (pA != pB){
          citysTree.gao(ds._min[pA], ds._max[pA] - 1).add(1, 0, maxrange, -ds._cnt[pA], false);
          stateTree.gao(ds._min[pA], ds._max[pA] - 1).add(1, 0, maxrange, -1, false);
          citysTree.gao(ds._min[pB], ds._max[pB] - 1).add(1, 0, maxrange, -ds._cnt[pB], false);
          stateTree.gao(ds._min[pB], ds._max[pB] - 1).add(1, 0, maxrange, -1, false);
          //cout  << citysTree.gao(0, maxrange).query(1, 0, maxrange) << endl;
          int pC = ds.join(A, B); 
          //cout << ds._cnt[pC] << ": " << ds._min[pC] << ", " << ds._max[pC] << endl;
          citysTree.gao(ds._min[pC], ds._max[pC] - 1).add(1, 0, maxrange, ds._cnt[pC], false);
          stateTree.gao(ds._min[pC], ds._max[pC] - 1).add(1, 0, maxrange, 1, false);
          //cout  << citysTree.gao(0, maxrange).query(1, 0, maxrange) << endl;
        }
      }else{
        assert(!strcmp(cmd, "line"));
        double dC; scanf("%lf", &dC);
        int C = floor(dC);
        //cout << C << endl;
        int citysNum = citysTree.gao(C, C).query(1, 0, maxrange);
        int stateNum = stateTree.gao(C, C).query(1, 0, maxrange); 
        printf("%d %d\n", stateNum, citysNum);
      }
    }
  }
}
开发者ID:LiaoZhuo,项目名称:Practice,代码行数:40,代码来源:uva_1455.cpp

示例2: solve

void solve()
{
    int n = readint();
    tree1.init(MAXC);
    tree2.init(MAXC);
    
    int i = 0;
    for(i = 0; i < n; i++)
    {
        City *p = &(cities[i]);
        readint();
        p->y = readint();
        p->ppa = p;
        p->minY = p->y;
        p->maxY = p->y;
        p->size = 1;
    }
    
    int m = readint();
    char cmd[16];    
    for(i = 0; i < m; i++)
    {
        scanf("%s", cmd);
        if(cmd[0] == 'r')
        {
            int A, B;
            A = readint(), B = readint();            
            connect(A, B);
        }
        else if(cmd[0] = 'l')
        {
            float C;
            scanf("%f", &C);
            int y = (int)C;
            pair<int, int> sd = make_pair(tree1.query(y, y), tree2.query(y, y));
            printf("%d %d\n", sd.first, sd.second);
        }
    }
}
开发者ID:lijiansong,项目名称:acm-algorithms,代码行数:39,代码来源:UVa1455++Kingdom.cpp

示例3: solve

i64 solve(vector<Rect> rects){
  compress(rects);
  vector<Event> evs = eventsFromRect(rects);
  i64 total = 0;
  IntervalTree::Node root = {1, 0, (int)xs.size() - 2};
  tree.init(root);
  for (size_t i = 0; i < evs.size(); i++){
    Event &e = evs[i];
    if (i != 0){
      i64 s = tree.gao(0, (int)xs.size() - 2).query(root, k);
      //printf("%lld\n", s);
      total += s * (ys[evs[i].tick] - ys[evs[i - 1].tick]);
    }
    //e.debug();
    //printf("%lu: %lld\n", i, total); 
    tree.gao(e.from, e.to).add(root, e.inc);
  }
  return total;
}
开发者ID:LiaoZhuo,项目名称:Practice,代码行数:19,代码来源:uva_11983.cpp


注:本文中的IntervalTree::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。