Ejemplo n.º 1
0
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;
				}
			}
		}
	}   
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
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;
    
}
Ejemplo n.º 6
0
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);
		}
	}
}
Ejemplo n.º 7
0
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);
}
Ejemplo n.º 8
0
void checkBounds()
{
    if ((trialMode!=PROBEMODE) )
    {
        conditionInside = ((projPoint - Vector3d(0,0,focalDistance) ).norm()) <= (circleRadius-2.5) ; // here we subtract 4 to work with trianglewave precision
        // If this condition is met, then this means that the point is outside the screen area!
        if ( !( conditionInside || (!wasInside) ) )
        {
            switch ( (int) factors["Anchored"] )
            {
            case 0:	//anchored x
                signsX.pop_back();
                signsX.push_front( factors["Onset"]* projPoint.x() > 0 );
                if ( (signsX.front() != signsX.back() ) )
                    sumOutside++;
                break;
            case 1:	//anchored x
                signsX.pop_back();
                signsX.push_front( factors["Onset"]* projPoint.x() > 0 );
                if ( (signsX.front() != signsX.back() ) )
                    sumOutside++;
                break;
            case 2:	//anchored y
                signsY.pop_back();
                signsY.push_front( factors["Onset"]*projPoint.y() > 0 );
                if ( (signsY.front() != signsY.back() ) )
                    sumOutside++;
                break;
            }
        }
        wasInside = conditionInside;
    }
}
Ejemplo n.º 9
0
Archivo: J.cpp Proyecto: mrain/acm
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;
}
Ejemplo n.º 10
0
 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();
 } 
Ejemplo n.º 11
0
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;
}
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);
    }
}
Ejemplo n.º 13
0
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;
}
Ejemplo n.º 14
0
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;
}
Ejemplo n.º 15
0
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);
		}
	}
}
Ejemplo n.º 16
0
  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;
  }
Ejemplo n.º 17
0
void switchBackground()
{
    backgrounds.push_back(backgrounds.front());
    backgrounds.pop_front();
    destroy_bitmap(currentBackground);
    currentBackground = load_bitmap(backgrounds.front().c_str(), NULL);
    blit(currentBackground, screen, 0, 0, 0, 0, currentBackground->w, currentBackground->h);
}
Ejemplo n.º 18
0
int main()
{
	scanf("%d%d",&n,&m),getchar();
	for (int i=0;i<=n*2;i++) gets(g[i]);
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++)
		{
			int x=i*2+1,y=j*2+1;
			if (g[x-1][y]=='.') adj[i+1][j+1].push_back(P(i,j+1)),adj[i][j+1].push_back(P(i+1,j+1));
			if (g[x+1][y]=='.') adj[i+1][j+1].push_back(P(i+2,j+1)),adj[i+2][j+1].push_back(P(i+1,j+1));
			if (g[x][y-1]=='.') adj[i+1][j+1].push_back(P(i+1,j)),adj[i+1][j].push_back(P(i+1,j+1));
			if (g[x][y+1]=='.') adj[i+1][j+1].push_back(P(i+1,j+2)),adj[i+1][j+2].push_back(P(i+1,j+1));
			if (g[x][y]=='1') si=i+1,sj=j+1;
			if (g[x][y]=='2') ti=i+1,tj=j+1;
		}
	for (int i=0;i<=n;i++)
	{
		adj[i][0].push_back(P(i+1,0));
		adj[i+1][0].push_back(P(i,0));
		adj[i][m+1].push_back(P(i+1,m+1));
		adj[i+1][m+1].push_back(P(i,m+1));
	}
	for (int i=0;i<=m;i++)
	{
		adj[0][i].push_back(P(0,i+1));
		adj[0][i+1].push_back(P(0,i));
		adj[n+1][i].push_back(P(n+1,i+1));
		adj[n+1][i+1].push_back(P(n+1,i));
	}
	d[si][sj][P(ti,tj)]=1;
	Q.push_back(make_pair(P(si,sj),P(ti,tj)));
	while (!Q.empty())
	{
		P s=Q.front().first,t=Q.front().second;
		//cout<<s.first<<","<<s.second<<" "<<t.first<<","<<t.second<<endl;
		Q.pop_front();
		int D=d[s.first][s.second][t];
		if ((s.first<1||s.first>n||s.second<1||s.second>m)&&(t.first<1||t.first>n||t.second<1||t.second>m))
		{
			printf("%d\n",D-1);
			return 0;
		}
		for (unsigned i=0;i<adj[s.first][s.second].size();i++)
		{
			P ss=adj[s.first][s.second][i];
			if (check(t,ss)&&!d[ss.first][ss.second][t])
				d[ss.first][ss.second][t]=D+dist(s,ss),dist(s,ss)?Q.push_back(make_pair(ss,t)):Q.push_front(make_pair(ss,t));
		}
		for (unsigned i=0;i<adj[t.first][t.second].size();i++)
		{
			P tt=adj[t.first][t.second][i];
			if (check(s,tt)&&!d[s.first][s.second][tt])
				d[s.first][s.second][tt]=D+dist(t,tt),dist(t,tt)?Q.push_back(make_pair(s,tt)):Q.push_front(make_pair(s,tt));
		}
	}
	puts("Death");
	return 0;
}
Ejemplo n.º 19
0
int main(){
	scanf("%d %d %d %d %d %d", &m, &n, &a, &b, &c, &d);

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			scanf("%d", &g[i][j]);

	for (int i = n; i >= 1; i--)
		for (int j = m; j >= 1; j--)
			s[i][j] = g[i][j] + s[i+1][j] + s[i][j+1] - s[i+1][j+1];

	for (int i = 2; i+d <= n; i++){
		q.clear();

		int j;
		for (j = 2; j+c < a; j++){
			while (!q.empty() && q.back().fst > inner(i,j))
				q.pop_back();
			q.push_back(mp(inner(i,j), mp(i,j)));
		}

		for (; j+c <= m; j++){
			if (j-a+c+1 > 1 && q.front().fst == inner(i, j-a+c+1))
				q.pop_front();
			while (!q.empty() && q.back().fst > inner(i,j))
				q.pop_back();
			q.push_back(mp(inner(i,j), mp(i,j)));
			h[i][j-a+c+2] = q.front();
		}
	}

	auto best = mp(-1, mp(mp(0,0), mp(0,0)));
	for (int j = 1; j+a <= m+1; j++){
		q.clear();

		for (int i = 2; i+d < b; i++){
			while (!q.empty() && q.back().fst > h[i][j+1].fst)
				q.pop_back();
			q.push_back(h[i][j+1]);
		}

		for (int i = 1; i+b <= n+1; i++){
			if (i > 1 && q.front().fst == h[i][j+1].fst)
				q.pop_front();
			while (!q.empty() && q.back().fst > h[i+b-d-1][j+1].fst)
				q.pop_back();

			q.push_back(h[i+b-d-1][j+1]);
			auto z = q.front();

			best = max(best,
			           mp(outer(i,j) - z.fst, mp(mp(i,j), z.snd))
				  );
		}
	}

	printf("%d %d\n%d %d\n", best.snd.fst.snd, best.snd.fst.fst, best.snd.snd.snd, best.snd.snd.fst);
}
Ejemplo n.º 20
0
inline void remove(int pos, int val) {
    while (!mx.empty() && mx.front().second <= pos) mx.pop_front();
    while (!mn.empty() && mn.front().second <= pos) mn.pop_front();
    while (!mx.empty() && mx.back().second <= pos) mx.pop_back();
    while (!mn.empty() && mn.back().second <= pos) mn.pop_back();
    if (mx.front().first - mn.front().first <= 1) {
        res = max(res, r - l - 1);
    }
}
    void pop() {
	//Pops an element from the front of Queue
	//Complexity - O(1), amortized
        
	if(Min.front() == D.front())
            Min.pop_front();
         
	D.pop_front();
    }
Ejemplo n.º 22
0
void printCountComparison(deque<std::string> top_words, deque<int> actual_result, deque<int> countmin_result,deque<int> insertcountmin_result){
	while(!top_words.empty()){
		printf("%s,%d,%d,%d\n",top_words.front().c_str(),actual_result.front(),countmin_result.front(),insertcountmin_result.front());
		top_words.pop_front();
		actual_result.pop_front();
		countmin_result.pop_front();
		insertcountmin_result.pop_front();
	}
}
Ejemplo n.º 23
0
void switchMusic()
{
    stop_sample(currentMusic);
    destroy_sample(currentMusic);
    music.push_back(music.front());
    music.pop_front();
    currentMusic = load_sample(music.front().c_str());
    play_sample(currentMusic, 255, 155, 1000, 1);
}
Ejemplo n.º 24
0
int main()
{
    scanf("%s%d",table+1,&k);len=strlen(table+1);
    for(int i=1;i<=len;i++)
    {
        if(isalpha(table[i]))
        {
            if(!vis[table[i]-'a'])k--;
            vis[table[i]-'a']=1;
        }else
        {
            if(i&1)odd++,odd_que.push(i);else even++,even_que.push(i);
        }
    }
    for(int i=0;i<=25;i++)if(!vis[i])dq.push_back(i);
    if(even+odd<k)
    {
        printf("-1\n");
        return 0;
    }
    int cnt=0;
    while(cnt<k)
    {
        if(26-dq.front()>dq.back())
        {
            if(!even_que.empty())
            {
                table[even_que.front()]=dq.front()+'a';
                even_que.pop();dq.pop_front();cnt++;
            }else
            {
                table[odd_que.front()]=dq.back()+'a';
                odd_que.pop();dq.pop_back();cnt++;
            }
        }else
        {
            if(!odd_que.empty())
            {
                table[odd_que.front()]=dq.back()+'a';
                odd_que.pop();dq.pop_back();cnt++;
            }else
            {
                table[even_que.front()]=dq.front()+'a';
                even_que.pop();dq.pop_front();cnt++;
            }
        }
    }
    for(int i=1;i<=len;i++)
    {
        if(table[i]=='?')
        {
            if(i&1)table[i]='z';else table[i]='a';
        }
    }
    printf("%s\n",table+1);
    return 0;
}
Ejemplo n.º 25
0
 void put(int key, int value) {
     if (cnt[key] == 0 && hash.size() == n) {
         while (!dq.empty() && --cnt[dq.front()] > 0) { dq.pop_front(); }
         hash.erase(dq.front());
         dq.pop_front();
     }
     dq.push_back(key);
     cnt[key]++;
     hash[key] = value;
 }
Ejemplo n.º 26
0
void moveToFront(int i, Xpp* xpp, Draw* draw) {
    xpp->resizeAndCenter(windows.front(), minW, minH);
    windows.push_front  (windows[i]);
    windows.erase       (windows.begin()+i+1);
    xpp->raise          (windows.front());
    xpp->focus          (windows.front());
    isBig               = false;
    draw->move          (windows.front(), 0);
    draw->update        ();
}
Ejemplo n.º 27
0
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d%d",&X[i],&H[i]);
		D.push_back( i );
	}
	int ans = 0;
	lr = MAXL, ll = -MAXL;
	while(!D.empty()){
		while(!D.empty() && ll < X[D.front()] - H[D.front()]){
			ans++; ll = X[D.front()]; D.pop_front();
		}
		while(!D.empty() && X[D.back()] + H[D.back()] < lr){
			ans++; lr = X[D.back()]; D.pop_back();
		}
		if(!D.empty()) ll = X[D.front()], lr = X[D.back()];
		// two sides CANNOT be cut outside
		if(!D.empty() && X[D.front()] + H[D.front()] < ( D.size() == 1 ? lr : X[D.front()+1] ) ){
			ans++; ll = X[D.front()] + H[D.front()];
		}
		if(!D.empty() && X[D.back()] - H[D.back()] > ( D.size() == 1 ? ll : X[D.back()-1] ) ){
			ans++; lr = X[D.back()] - H[D.back()];
		}
		if(!D.empty()) D.pop_front();
		if(!D.empty()) D.pop_back();
	}
	printf("%d",ans);
	return 0;
}
Ejemplo n.º 28
0
int main(){
    while(T-- && ~(scanf("%d",&N))){
        qmax.clear();
        qmin.clear();
        int ans = 0;
        int l = 1;
        for (int i = 1;i <= N;i++){
            scanf("%d",&tmp.val);
            tmp.num = i;
            while(!qmax.empty() && tmp.val > qmax.back().val) qmax.pop_back();
            qmax.push_back(tmp);
            while(!qmin.empty() && tmp.val < qmin.back().val) qmin.pop_back();
            qmin.push_back(tmp);
            while(qmax.front().val-qmin.front().val > 1){
                if (qmax.front().num > qmin.front().num){
                    l = max(l,qmin.front().num+1);
                    qmin.pop_front();
                }
                else if (qmax.front().num < qmin.front().num){
                    l = max(l,qmax.front().num+1);
                    qmax.pop_front();
                }
                else{
                    l = max(l,qmax.front().num+1);
                    qmin.pop_front(), qmax.pop_front();
                }
            }
            ans = max(ans,i-l+1);
        }
        printf("%d\n",ans);
    }
    return 0;
}
Ejemplo n.º 29
0
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i < k; ++i) {
        Node t;
        t.id = i;
        t.num = a[i];
        while (!deq.empty() && deq.back().num >= t.num) {
            deq.pop_back();
        }
        deq.push_back(t);
    }
    for (int i = k; i <= n; ++i) {
        Node t;
        t.id = i;
        t.num = a[i];
        while (!deq.empty() && deq.back().num >= t.num) {
            deq.pop_back();
        }
        deq.push_back(t);
        while (!deq.empty() && deq.front().id <= i - k) {
            deq.pop_front();
        }
        printf("%d ",deq.front().num);
    }
    printf("\n");
    deq.clear();
    for (int i = 1; i < k; ++i) {
        Node t;
        t.id = i;
        t.num = a[i];
        while (!deq.empty() && deq.back().num <= t.num) {
            deq.pop_back();
        }
        deq.push_back(t);
    }
    for (int i = k; i <= n; ++i) {
        Node t;
        t.id = i;
        t.num = a[i];
        while (!deq.empty() && deq.back().num <= t.num) {
            deq.pop_back();
        }
        deq.push_back(t);
        while (!deq.empty() && deq.front().id <= i - k) {
            deq.pop_front();
        }
        printf("%d ",deq.front().num);
    }
    printf("\n");
    return 0;
}
Ejemplo n.º 30
0
void solve() {
	dq.clear();
	for (int i = 1; i <= k; ++i) push(i);
	printf("%d", a[dq.front()]);
	for (int j = k + 1; j <= n; ++j) {
		pop(j - k);	push(j);
		printf(" %d", a[dq.front()]);
	}

	printf("\n");
}