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


C++ map::upper_bound方法代码示例

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


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

示例1: main

int main() {

    int n,W,H;
    while(~scanf("%d%d%d",&n,&W,&H)) {
        init();
        maxbright = 0;
        for(int i = 0;i < n;i ++) {
            scanf("%d%d%d",&all[i].x,&all[i].y,&all[i].shine);
            mapy[all[i].y] = 0;
        }
        sort(all,all+n,cmp);
        int countf = 0;
        for(map<int ,int >::iterator it = mapy.begin();it != mapy.end();it ++) {
            countf ++;
            it -> second = countf;
        }
        int i,j ;
        i = 0;j= 0;
        while(i < n) {

            while(all[i].x - all[j].x >=  W) {
                add(1,countf,1,-all[j].shine,mapy.upper_bound(all[j].y - H) -> second,mapy[all[j].y]);
                j ++;
            }
            add(1,countf,1,all[i].shine,mapy.upper_bound(all[i].y - H) -> second,mapy[all[i].y]);
            maxbright = max(maxbright,getMax());
            i ++;
        }
        printf("%d\n",maxbright);
    }


}
开发者ID:Yelrose,项目名称:SicilyCode,代码行数:33,代码来源:1092_Stars_in_Your_Window.cpp

示例2: solve

long long  solve(long long  x){
    long long  res = 0;
    int r = 0, l = 0;
    queue<STAR> q;
    for(int i = 0;i < n;i++){
	if(stars[i].second != x)continue;
	while(stars[r].first.first < stars[i].first.first - x)r++;
	while(l < n && stars[i].first.first >= stars[l].first.first - x) l++;
	i = l;
	for(;r < l;r++){
	    if(stars[r].second < x)continue;
	    q.push(stars[r]);
	    while(!q.empty() && q.front().first.first  < stars[r].first.first - x){
		STAR tmp = q.front();q.pop();
		map<long long, long long>::iterator it = zahyou.upper_bound(tmp.first.second + x);
		add_segtree(zahyou[tmp.first.second], (*--it).second, root, -1);
	    }
	    map<long long, long long>::iterator it = zahyou.upper_bound(stars[r].first.second + x);
	    add_segtree(zahyou[stars[r].first.second], (*--it).second, root, 1);
	    res = max(res, root -> all + root -> maximum);
	}
	r = i;
    }
    while(!q.empty()){
	STAR tmp = q.front();q.pop();
	map<long long, long long>::iterator it = zahyou.upper_bound(tmp.first.second + x);
	add_segtree(zahyou[tmp.first.second], (*--it).second, root, -1);
    }  
    return res;
}
开发者ID:catupper,项目名称:JOISS,代码行数:30,代码来源:StarrySkyg.cpp

示例3: scanAscending

 void scanAscending(RecordListResponse& _return, const map<string, string>& mymap,
           const string& startKey, const bool startKeyIncluded,
           const string& endKey, const bool endKeyIncluded,
           const int32_t maxRecords, const int32_t maxBytes) {
     map<string, string>::const_iterator itr = startKeyIncluded ? 
         mymap.lower_bound(startKey):
         mymap.upper_bound(startKey);
     int numBytes = 0;
     while (itr != mymap.end()) {
         if (!endKey.empty()) {
             if (endKeyIncluded && endKey < itr->first) {
               break;
             }
             if (!endKeyIncluded && endKey <= itr->first) {
               break;
             }
         }
         Record record;
         record.key = itr->first;
         record.value = itr->second;
         numBytes += record.key.size() + record.value.size();
         _return.records.push_back(record);
         if (_return.records.size() >= (uint32_t)maxRecords || numBytes >= maxBytes) {
             _return.responseCode = ResponseCode::Success;
             return;
         }
         itr++;
     }
     _return.responseCode = ResponseCode::ScanEnded;
 }
开发者ID:BigR-Lab,项目名称:mapkeeper,代码行数:30,代码来源:StlMapServer.cpp

示例4: main

int main()
{
	int T;
	cin >> T;
	while(T--)
	{
		cin >> N;
		init();
		M.clear();
		for(int t = 0; t < N; t++)
		{
			int x;
			scanf("%d", &x);
			//printf("input %d\n", x);
			//for(map<int, int>::iterator it = M.begin(); it != M.end(); it++)
				//printf("%d ", it->first);
			//cout << endl;
			map<int, int>::iterator it = M.upper_bound(x + 1);
			if(it == M.begin())
			{
				int i = insert(x, -1, head);
				M[x] = i;
			}
			else
			{
				it--;
				int i = insert(x, it->second, list[it->second][2]);
				if(it->first == x + 1) M.erase(it);
				M[x] = i;
			}
			//print();
		}
		print();
	}
}
开发者ID:1ridescent,项目名称:ACM,代码行数:35,代码来源:C1.cpp

示例5: addNum

 void addNum(int val)
 {
   if (intervals_.empty()) {
     intervals_[val] = val;
     return;
   }
   auto ub = intervals_.upper_bound(val);
   if (ub == intervals_.begin()) {
     if (ub->first - 1 == val) {
       intervals_[val] = ub->second;
       intervals_.erase(ub);
     } else
       intervals_[val] = val;
   } else {
     auto p = prev(ub);
     if (ub == intervals_.end() || ub->first - 1 > val) {
       if (p->second + 1 < val)
         intervals_[val] = val;
       else if (p->second + 1 == val)
         p->second = val;
     } else {
       if (p->second + 1 < val)
         intervals_[val] = ub->second;
       else if (p->second + 1 == val)
         p->second = ub->second;
       intervals_.erase(ub);
     }
   }
 }
开发者ID:gongzhitaao,项目名称:oj,代码行数:29,代码来源:352-data-stream-as-disjoint-intervals.cpp

示例6: work

bool work(int t, int m) {
	int x = max_x[0];
	rep(i, m) {
		auto next = yc.upper_bound(max_y[xc.lower_bound(x - t)->snd] + t);
		if(next == yc.end()) return true;
		x = max_x[next->snd];
	}
开发者ID:md143rbh7f,项目名称:competitions,代码行数:7,代码来源:TheEmpireStrikesBack.cpp

示例7:

string
find_symbol (int addr)
{
  map<uint16_t,string>::iterator mi;
  mi = exports.upper_bound(addr);

  if (exports.empty() || mi == exports.begin())
    {
      std::stringstream ss;
      ss << '$' << std::hex << addr;
      return ss.str();
    }
  else
    {
      mi--;
      if (mi->first == addr)
	return mi->second;
      else
        {
	  std::stringstream ss;
	  ss << mi->second << "+" << addr - mi->first;
	  return ss.str();
	}
    }
}
开发者ID:groessler,项目名称:gcc-6502-bits,代码行数:25,代码来源:mapfile.cpp

示例8: get_value

		/* This function returns the minimum/maximum value at x. */
		double get_value(double x)
		{	
			map<double, Line>::iterator it = query_set.upper_bound(x);
			it--;

			return x*it->s.m + it->s.c;
		}
开发者ID:achiever202,项目名称:Competitive-Programming,代码行数:8,代码来源:Convex+Hull+Trick.cpp

示例9: f

string f (int x) {
  auto up = mapa.upper_bound(x);
  up --;
  int key = up -> first;

  if (key == x) return mapa[x];
  return mapa[key] + f(x - key);
}
开发者ID:jhonber,项目名称:Programming-Contest,代码行数:8,代码来源:1960.cpp

示例10: canInsert

bool canInsert(int p, int q)
{
	auto upper = nerds.upper_bound(p);
	if (upper == nerds.end()) return true;


	return upper->second <= q;
}
开发者ID:MinWooJin,项目名称:algoritim_study,代码行数:8,代码来源:NERD2.cpp

示例11: main

int main() {
	int q;
	cin >> q;
	
	char c;
	int x, l, h, t, b;
	while (q--) {				
		// cin >> c >> x;
		scanf(" %c %d", &c, &x); // faster than cin
		if (c == '+') {
			hmap[x]++;
		} else if (c == '-'){
			hmap[x]--;
			if (hmap[x] == 0)
				hmap.erase(x);			
		} else { // find max value
			l = 0;
			h = ((ll)1 << 31) - 1;
			t = h ^ x; // this is the target we want to find in A

			for (int i = 30; i >= 0; i--) {
				b = t & (1 << i);
				if (b) { // i th target bit is 1
					h = h | (1 << i);
					l = l | (1 << i);
					if (hmap.lower_bound(l) == hmap.upper_bound(h)) { // no value between l and h
						// reverse
						h = h & (~(1 << i));
						l = l & (~(1 << i));
					}
				} else {
					h = h & (~(1 << i));
					l = l & (~(1 << i));
					if (hmap.lower_bound(l) == hmap.upper_bound(h)) { // no value between l and h
						h = h | (1 << i);
						l = l | (1 << i);
					}
				}
			}
			cout << max(x, l^x) << endl;
		}		
	}	
	return 0;
}
开发者ID:flyingmouse,项目名称:Codeforces,代码行数:44,代码来源:D.cpp

示例12: main

int main(){
    scanf("%d %d",&n,&m);
    low.insert(0);
    low.insert(n);
    high.insert(n);
    high.insert(2*n);
    for(int i=0; i<m; i++){
        char b[5];
        int x, y;
        scanf("%s %d %d",b,&x,&y);
        if(*b == 'B'){
            if(x > y) swap(x, y);
            if(y <= n){
                low.insert(x);
            }
            else{
                high.insert(x);
            }
        }
        if(*b == 'Q'){
            if((x-1) / n == (y-1) / n){
                if(x <= n && x > y){
                    auto u = mp1.lower_bound(x);
                    auto v = low.lower_bound(x);
                    if(u == mp1.end() || (v != low.end() && *v < u->first)) puts("NE");
                    else move(u->second, y);
                }
                else if(x <= n && x <= y){
                    auto t = low.lower_bound(x);
                    puts(y <= *t ? "DA" : "NE");
                }
                else if(x > n && x >= y){
                    auto t = --high.lower_bound(x);
                    puts(*t+1 <= y ? "DA" : "NE");
                }
                else{
                    auto u = mp2.upper_bound(x);
                    auto v = high.lower_bound(x);
                    if(u == mp2.begin()) puts("NE");
                    else{
                        u--;
                        if(v != high.begin() && *--v >= u->first){
                            puts("NE");
                        }
                        else move(u->second, y);
                    }
                }
            }
            else move(x, y);
        }
        if(*b == 'A'){
            if(x > y) swap(x, y);
            ins(x, y);
        }
    }
}
开发者ID:koosaga,项目名称:olympiad,代码行数:56,代码来源:coi14_mostovi.cpp

示例13: query

bool query(int sx, int ex, int sy, int ey){
    auto itl = mp1.lower_bound(sx);
    auto itr = mp1.upper_bound(ex);
    if(itl == mp1.end() || itl->first > ex) return 0;
    if(itl->second > ey) return 0;
    itr--;
    if(itr->second < sy) return 0;
    auto ity = mp2.lower_bound(sy);
    if(ity == mp2.end() || ity->first > ey) return 0;
    return 1;
}
开发者ID:koosaga,项目名称:olympiad,代码行数:11,代码来源:coi14_mostovi.cpp

示例14: get

struct Node* get(size_t key){
	struct Node* getNode;
	map<size_t, struct Node*>::iterator it = consistentHash.upper_bound(key);
	if (it == consistentHash.end()){
		getNode = consistentHash.begin()->second;
	}
	else{
		getNode = it->second;
	}

	return getNode;
}
开发者ID:rrodrigoa,项目名称:SimpleConsistentHash,代码行数:12,代码来源:main.cpp

示例15: gao

bool gao()
{
	int a,b;
	map<int,int>::iterator it;
	scanf("%d%d",&a,&b);
	it=mp0.lower_bound(a);
	if(b<it->second) return 0;
	it=mp1.upper_bound(a);
	--it;
	if(b>it->second) return 0;
	return 1;
}
开发者ID:shad0w-walker233,项目名称:ICPC,代码行数:12,代码来源:1008.cpp


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