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


C++ deque::front方法代码示例

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


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

示例1: bfs

void bfs(int y, int x)
{  
	q.push_back(make_pair(make_pair(y,x),0)); 
	v[y][x]=1;
	while(!q.empty())
	{
		int deqh=q.front().first.first;
		int deqw=q.front().first.second;
		int deqc=q.front().second;
		q.pop_front();
		for(int i=0;i<4;i++)
		{
			int nx=deqw+dx[i];
			int ny=deqh+dy[i];
			if(nx>=0&&nx<w&&ny>=0&&ny<h&&!v[ny][nx])
			{ 
				if(!arr[ny][nx]) 
					// 0을 모두 방문해야하니, 앞으로 넣어준다. 그래야 다음 deq값도 0이 나오기 때문.
				{
					q.push_front(make_pair(make_pair(ny,nx),deqc));
					arr2[ny][nx]=deqc; // 배열을 하나 더 써야 원본맵 정보가 섞이지 않는다.
					v[ny][nx]=1;
				}
				else // 벽에 막혀 못 가는 경우라면 뒤로 넣어준다. 그래야 그 값을 새로 열린 길이라 여기고 bfs하기 때문.
				{ 
					q.push_back(make_pair(make_pair(ny,nx),deqc+1));
					arr2[ny][nx]=deqc+1;
					v[ny][nx]=1;
				}
			}
		}
	}   
}
开发者ID:imgosari,项目名称:acm,代码行数:33,代码来源:완전탐색_알고스팟.cpp

示例2: BackgroundDef

BackgroundDef BackgroundImpl::Layer::CreateRandomBGA( const Song *pSong, const RString &sEffect, deque<BackgroundDef> &RandomBGAnimations, Actor *pParent )
{
	if( g_RandomBackgroundMode == BGMODE_OFF )
		return BackgroundDef();

	// Set to not show any BGChanges, whether scripted or random
	if( GAMESTATE->m_SongOptions.GetCurrent().m_bStaticBackground )
		return BackgroundDef();

	if( RandomBGAnimations.empty() )
		return BackgroundDef();

	/* XXX: every time we fully loop, shuffle, so we don't play the same sequence
	 * over and over; and nudge the shuffle so the next one won't be a repeat */
	BackgroundDef bd = RandomBGAnimations.front();
	RandomBGAnimations.push_back( RandomBGAnimations.front() );
	RandomBGAnimations.pop_front();

	if( !sEffect.empty() )
		bd.m_sEffect = sEffect;

	map<BackgroundDef,Actor*>::const_iterator iter = m_BGAnimations.find( bd );

	// create the background if it's not already created
	if( iter == m_BGAnimations.end() )
	{
		bool bSuccess = CreateBackground( pSong, bd, pParent );
		ASSERT( bSuccess );	// we fed it valid files, so this shouldn't fail
	}
	return bd;
}
开发者ID:dtinth,项目名称:stepmania,代码行数:31,代码来源:Background.cpp

示例3: Modlabel

bool Modlabel(int src, int des, int n) {
    int i, j, u, v, c, w, del;
    memset(dist, 0x3f, sizeof(dist[0])*(n + 3));
    dist[src] = 0;
    while(!Q.empty()) Q.pop_back();
    Q.push_back(src);
    while(!Q.empty()) {
        u = Q.front(); Q.pop_front();
        for(j = last[u]; j != -1; j = e[j].next) {
            v = e[j].v; c = e[j].c; w = e[j].w;
            if(c && (del = dist[u] + w) < dist[v]) {
                dist[v] = del;
                if(Q.empty() || del <= dist[Q.front()]) {
                    Q.push_front(v);
                }
                else {
                    Q.push_back(v);
                }
            }
        }
    }
    for(i = 0; i < n; i++) {
        for(j = last[i]; j != -1; j = e[j].next) {
            e[j].w -= dist[e[j].v] - dist[i];
        }
    }
    value += dist[des];
    return dist[des] < MOD;
}
开发者ID:Fengdalu,项目名称:ICPC,代码行数:29,代码来源:2135_2.cpp

示例4: main

int main()
{
    int N, W; scanf("%d%d", &N, &W);
    for(int i=0; i<N; ++i) {
        scanf("%d", vals + i);
    }

    int ans=0;
    if (W==1) { printf("%d\n", N); return 0; }

    minque.push_back(pii(vals[0], 0));
    maxque.push_back(pii(vals[0], 0));
    for(int i=1; i<N; ++i) {
        if (minque.front().second <= i-W) minque.pop_front();
        if (maxque.front().second <= i-W) maxque.pop_front();
        while(!minque.empty() && vals[i] <= minque.back().first) {
            minque.pop_back();
        }
        minque.push_back(pii(vals[i], i));
        while(!maxque.empty() && vals[i] >= maxque.back().first) {
            maxque.pop_back();
        }
        maxque.push_back(pii(vals[i], i));
        if (i>=W-1) {
            int mm, xx;
            mm = minque.front().first;
            xx = maxque.front().first; //printf("%d %d\n", mm, xx);
            if (xx - mm == W-1) ans++;
        }
    }
    printf("%d\n", ans);
}
开发者ID:lantimilan,项目名称:topcoder,代码行数:32,代码来源:CHEFTOWN.cpp

示例5: packageWiFiInfo

int phoneDataParse::packageWiFiInfo(deque<WiFiInfo> wifilist, string &str)
{

    cJSON *wifiList;
    cJSON *wifiInfoJson;
    cJSON *wifiInfoArray;
    
    wifiInfoArray = cJSON_CreateArray();

    char *temp;
    while(wifilist.size())
    {
	wifiInfoJson = cJSON_CreateObject();

	cJSON_AddItemToObject(wifiInfoJson, "SSId", cJSON_CreateString(wifilist.front().ssid));
	temp = const_cast<char *>(intToStr(wifilist.front().rssi).c_str()); 
	cJSON_AddItemToObject(wifiInfoJson, "RSSI", cJSON_CreateString(temp));
	cJSON_AddItemToObject(wifiInfoJson, "encryption", cJSON_CreateString(wifilist.front().encryption));
	cJSON_AddItemToArray(wifiInfoArray, wifiInfoJson);
	wifilist.pop_front();
    }

    wifiList = cJSON_CreateObject();
    cJSON_AddItemToObject(wifiList, "sysID", cJSON_CreateString("0150"));
    cJSON_AddItemToObject(wifiList, "optCode", cJSON_CreateString("0020"));
    cJSON_AddItemToObject(wifiList, "timeOut", cJSON_CreateString("22222222222"));
    cJSON_AddItemToObject(wifiList, "WiFiListArray", wifiInfoArray);

    str = cJSON_Print(wifiList);

    return 0;
    
}
开发者ID:maquanhong,项目名称:emacs,代码行数:33,代码来源:phoneDataParse.cpp

示例6: threadedFunction

void ofURLFileLoaderImpl::threadedFunction() {
	ofLogVerbose("ofURLFileLoader") << "threadedFunction(): starting thread";
	lock();
	while( isThreadRunning() == true ){
		if(requests.size()>0){
	    	ofLogVerbose("ofURLFileLoader") << "threadedFunction(): querying request " << requests.front().name;
			ofHttpRequest request(requests.front());
			unlock();

			ofHttpResponse response(handleRequest(request));

			lock();
			if(response.status!=-1){
				// double-check that the request hasn't been removed from the queue
				if( (requests.size()==0) || (requests.front().getID()!=request.getID()) ){
					// this request has been removed from the queue
					ofLogVerbose("ofURLFileLoader") << "threadedFunction(): request " << requests.front().name
					<< " is missing from the queue, must have been removed/cancelled";
				}
				else{
					ofLogVerbose("ofURLFileLoader") << "threadedFunction(): got response to request "
					<< requests.front().name << " status " <<response.status;
					responses.push(response);
					requests.pop_front();
				}
			}else{
				responses.push(response);
		    	ofLogVerbose("ofURLFileLoader") << "threadedFunction(): failed getting request " << requests.front().name;
			}
		}else{
			ofLogVerbose("ofURLFileLoader") << "threadedFunction(): stopping on no requests condition";
			condition.wait(mutex);
		}
	}
}
开发者ID:BonjourDpt,项目名称:openFrameworks,代码行数:35,代码来源:ofURLFileLoader.cpp

示例7: solve

void solve()
{
    int sol = -1, st;
    int m, l = X, r = Y, g;
    while( l<=r ) {
        m = (l+r)>>1; g = 0;
        q.clear(); q2.clear();
        for(int i=1; i<=N; i++) {
            while( !q.empty() && A[i]<A[q.back()] ) q.pop_back(); //min
            q.push_back(i);
            while( !q2.empty() && A[i]>A[q2.back()] ) q2.pop_back(); //max
            q2.push_back(i);
            if( i<m ) continue;
            if( A[q2.front()]-A[q.front()]<=Z && m>=sol ) {
                sol = m; st = i-m+1;
                g = 1;
            }
            while( i-q.front()+1==m ) q.pop_front();
            while( i-q2.front()+1==m ) q2.pop_front();
        }
        if(g) l = m+1;
        else r = m-1;
    }

    sol == -1 ? printf("-1") : printf("%d %d %d", sol, st, st+sol-1);
}
开发者ID:george-popoiu,项目名称:infoarena_campion,代码行数:26,代码来源:sir2.cpp

示例8: check

bool check(int x)
{
	v.clear();
	for(int i=0;i<n;++i)
		v.push_back(hf(p[i],p[(i+x)%n]));
	//stable_sort(v.begin(),v.end(),cmp);
	static deque<hf> q;
	static deque<point> ans;
	q.clear(), ans.clear();
	q.push_back(v[0]);
	for(int i=1;i<(int)v.size();++i){
		//if(sgn(ang(v[i].B-v[i].A)-ang(v[i-1].B-v[i-1].A))==0)continue;
		while(ans.size()&&!satisfy(ans.back(),v[i]))
			ans.pop_back(),q.pop_back();
		while(ans.size()&&!satisfy(ans.front(),v[i]))
			ans.pop_front(),q.pop_front();
		if(parallel(q.back(),v[i]))return false;
		ans.push_back(intersect(q.back(),v[i]));
		q.push_back(v[i]);
	}
	while(ans.size()&&!satisfy(ans.back(),q.front()))
		ans.pop_back(),q.pop_back();
	if(parallel(q.back(),q.front()))return false;
	ans.push_back(intersect(q.back(),q.front()));
	double ret=cross(ans.back(),ans.front());
	for(int i=0;i<(int)ans.size()-1;++i)
		ret+=cross(ans[i],ans[i+1]);
	return fabs(ret)>=eps;
//	return OK;
}
开发者ID:mrain,项目名称:acm,代码行数:30,代码来源:J.cpp

示例9: insert

 void insert( Rect r ) {
     M[r.clr] += r.area();
     Q.push_back( r );
     while( Q.front().clr != -1 ) {
         Rect    z = Q.front();
         Q.pop_front();
         if( z.x1 >= r.x2 || z.x2 <= r.x1 ||
             z.y1 >= r.y2 || z.y2 <= r.y1 ) {
             Q.push_back( z );
             continue;
         }
         if( z.x1 < r.x1 ) {
             Q.push_back( Rect( z.x1, z.y1, r.x1, z.y2, z.clr ) );
             z.x1 = r.x1;
         }
         if( z.x2 > r.x2 ) {
             Q.push_back( Rect( r.x2, z.y1, z.x2, z.y2, z.clr ) );
             z.x2 = r.x2;
         }
         if( z.y1 < r.y1 ) {
             Q.push_back( Rect( z.x1, z.y1, z.x2, r.y1, z.clr ) );
             z.y1 = r.y1;
         }
         if( z.y2 > r.y2 ) {
             Q.push_back( Rect( z.x1, r.y2, z.x2, z.y2, z.clr ) );
             z.y2 = r.y2;
         }
         if( ( M[z.clr] -= z.area() ) == 0 ) M.erase( M.find( z.clr ) );
     }
     Q.push_back( Q.front() );
     Q.pop_front();
 } 
开发者ID:3013216027,项目名称:zoj-solutions-fish_ball,代码行数:32,代码来源:p1565.cpp

示例10: spfa

bool spfa(int st)
{
    for (int i=0;i<=V;i++)
    {
        dist[i] = INF;
    }
    dist[st] = 0;
    visited[st] = true;
    pqu.push_front(st);
    while(!pqu.empty()){
        int now = pqu.front();
        pqu.pop_front();
        visited[now] = false;
        for (int nt = first[now];nt!=0;nt = edges[nt].next){
            if (edges[nt].d + dist[now] < dist[edges[nt].y] ) {
                dist[edges[nt].y] =  edges[nt].d + dist[now];
                last[edges[nt].y] = now;
                if (!visited[edges[nt].y]){
                    visited[edges[nt].y] = true;
                    cnt[edges[nt].y]++;
                    if (cnt[edges[nt].y]>V) return false;
                    if (!pqu.empty()){
                        if (dist[edges[nt].y]>dist[pqu.front()])
                            pqu.push_back(edges[nt].y);
                        else
                            pqu.push_front(edges[nt].y);
                    } else pqu.push_front(edges[nt].y);
                }
            }
        }
    }
    return true;
}
开发者ID:LiWeiJie,项目名称:ACM-Code,代码行数:33,代码来源:spfa.cpp

示例11: DoPulse

void CSocketManager::DoPulse()
{
    // Loop through all sockets
    processQueue = deque <CSocket*>(vecSockets.begin(), vecSockets.end());
    while (!processQueue.empty())
    {
        CSocket* pSocket = processQueue.front();
        processQueue.pop_front();

        // Do a pulse at the socket
        if (!pSocket->DoPulse())
        {
            // If the pulse indicates failure, remove the socket
            SocketRemove(pSocket);
        }
    }

    // Finally cleanup sockets that were removed
    while (!deleteList.empty())
    {
        CSocket* pSocket = deleteList.front();
        deleteList.pop_front();
        SAFE_DELETE(pSocket);
    }
}
开发者ID:CarlchenHD,项目名称:multitheftauto-modules,代码行数:25,代码来源:CSocketManager.cpp

示例12: main

int main() {
    pair<int, int> idx;
    int d, t;
    scanf("%d", &t);
    for(int i=1; i<=t; i++) {
        scanf("%d", &d);
        dq.push_back(make_pair(d,i));
    }
    while(!dq.empty()) {
        idx = dq.front();
        dq.pop_front();
        if(idx.first>0) {
            for(int i=1; i<idx.first; i++) {
                dq.push_back(dq.front());
                dq.pop_front();
            }
        }
        else {
            idx.first = -idx.first;
            for(int i=0; i<idx.first; i++) {
                dq.push_front(dq.back());
                dq.pop_back();
            }
        }
        printf("%d ", idx.second);
    }
    return 0;
}
开发者ID:sency90,项目名称:allCode,代码行数:28,代码来源:2346.cpp

示例13: main

int main()
{
      int n,d;
      scanf("%d %d",&n,&d);
      int m,f;
      LL sum=0;
      LL ans=0;
      for(int i=0; i<n; ++i)
      {
            scanf("%d %d",&m,&f);
            ve.push_back(node(m,f));
      }
      sort(ve.begin(),ve.end());
      for(int i=0; i<n; ++i)
      {
            dq.push_front(ve[i]);
            sum+=ve[i].f;
            node b=dq.back();
            node f=dq.front();
            while(abs(b.m-f.m)>=d)
            {
                  sum-=b.f;
                  dq.pop_back();
                  b=dq.back();
                  f=dq.front();
            }
            ans=max(ans,sum);
      }
      printf("%I64d\n",ans);
      return 0;
}
开发者ID:ASIAH304,项目名称:ACM-ICPC,代码行数:31,代码来源:main.cpp

示例14: solve

void solve(){
	next = n + 1;
	pos = n;
	deq.clear();
	memset(s, 0, sizeof s);
	memset(times, 0, sizeof times);
	for(int i = n; i; --i){
		times[a[i]]++;
		s[i] = s[i + 1] + a[i];
		if(a[i] == 1)
			next = i;
		while(!deq.empty() && a[i] >= deq.back().first)
			deq.pop_back();
		deq.push_back(make_pair(a[i], i));
		while(!deq.empty() && deq.front().second > next)
			deq.pop_front();
		if(times[a[i]] > 1){
			do{
				times[a[pos]]--;
				if(!deq.empty() && deq.front().second == pos)
					deq.pop_front();
				pos--;
			} while(times[a[i]] > 1);
		}
		if(!deq.empty() && pos >= next){
			long long tmp = deq.front().first;
			if(pos >= i + tmp - 1 && s[i] - s[i + tmp] == (tmp + 1) * tmp / 2)
				ans = max(ans, (int)tmp);
		}
	}
}
开发者ID:quietshu,项目名称:Algorithm-Contests-Codes,代码行数:31,代码来源:LPERMUT.cpp

示例15: sub

  int sub(deque<pair<int,pair<long long, long long> > > price_and_mask, long long signature, int sum) {//, int cut=0) {
	int size = price_and_mask.size();
	if (size == 0) return 0;
	if (size == 1) return -(price_and_mask.front().first);
	if (m.find( signature ) != m.end()) return m[ signature ];
	
	long long sold_out = price_and_mask.front().second.second;
	//	vector< pair<int,long long> > price_sub1;
	deque< pair<int,pair<long long, long long> > > price_sub1;
	long long new_signature = 0;
	int sum1 = 0;
	tr(price_and_mask,it) {
	  if ((sold_out & it->second.second) == 0) {
		price_sub1.push_back( *it );
		new_signature |= it->second.first;
		sum1 -= it->first;
	  }
	}
	int amount1 = - price_and_mask.front().first + sub(price_sub1, new_signature, sum1);

	sum -= price_and_mask.front().first;
	if (sum < amount1) {
	  m[ signature ] = amount1;
	  return amount1;
	} 

	new_signature = signature - price_and_mask.front().second.first;
	price_and_mask.pop_front();

	int amount = max(amount1, sub(price_and_mask, new_signature, sum));
	m[ signature ] = amount;
	return amount;
  }
开发者ID:naoyat,项目名称:topcoder,代码行数:33,代码来源:StampsCollection_4a.cpp


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