//可以得到以idx/2为中心的串的左右端点。
PII getLR(int idx)
{
    int val = len[idx];
    if(idx&1){
        return PII(idx/2-val+1, idx/2+val);
    }else{
        return PII(idx/2-val+1, idx/2+val-1);
    }
}
示例#2
0
void dijkstra(int s) {
	priority_queue<PII, vector<PII>, greater<PII> > que;
	clr(dis, INF);
	dis[s] = 0;
	que.push(PII(0, s));
	while (!que.empty()) {
		PII p = que.top(); que.pop();
		int v = p.se;
		if (dis[v] < p.fi) continue;
		for (int i = head[v]; i != -1; i = e[i].next) {
			int u = e[i].to, cost = e[i].cost;
			if (dis[u] > dis[v] + cost) {
				dis[u] = dis[v] + cost;
				que.push(PII(dis[u], u));
			}
		}
	}
}
示例#3
0
void PowerWordRep::pushGeneratorFront( int g , int p )
{
  if( !theLength ) {
    theElements.push_front( PII(g,p) );
    theLength += abs(p);
  } else {
    PII& e = *theElements.begin();
    int g1 = e.first;
    int p1 = e.second;
    if( g1!=g ) {
      theElements.push_front( PII(g,p) );
      theLength += abs(p);
    } else {
      theLength -= abs( p1 );
      if( p1+p ) {
	e.second = p1+p;
	theLength += abs( p1+p );
      } else
	theElements.pop_front( );
    }
  }
}
示例#4
0
int bfsw( int x , int y )
{
	queue < pair < PII , int > > q;
	q.push( make_pair( PII( x , y ) , 0 ) );
	while( !q.empty() )
	{
		x = q.front().fr.fr;
		y = q.front().fr.se;
		int dd = q.front().se;
		q.pop();
		
		for( int i = -1 ; i < 2 ; i ++ )
			for( int j = -1 ; j < 2 ; j ++ )
				
		if( w[x+i][y+j]==0 && x+i <n && x+i>=0 && y+i <n && y+i>=0 && s[x+i][y+j]!='#')
				{
					w[x+i][y+j]=dd+1;
					q.push( make_pair( PII( x+i , y+j ) , dd+1 ) );
				}
	}
	return -1;
}
示例#5
0
int BFS( int x , int y , int s , int t )
{
	queue < pair < PII , int > > q;
	q.push( make_pair( PII( x , y ) , 0 ) );
	while( !q.empty() )
	{
		x = q.front().fr.fr;
		y = q.front().fr.se;
		int dd = q.front().se;
		q.pop();
		if( x == s && y == t )
			return dd;
		for( int i = -1 ; i < 2 ; i ++ )
			for( int j = -1 ; j < 2 ; j ++ )
				if( avail.find( PII( x+i , y+j ) ) != avail.end() )
				{
					avail.erase( avail.find( PII( x+i , y+j ) ) );
					q.push( make_pair( PII( x+i , y+j ) , dd+1 ) );
				}
	}
	return -1;
}
示例#6
0
void PowerWordRep::pushGeneratorBack( int g , int p )
{
  if( !theLength ) {
    theElements.push_back( PII(g,p) );
    theLength += abs(p);
  } else {
    PII& e = *(--theElements.end());
    int g1 = e.first;
    int p1 = e.second;
    if( g1!=g ) {
      theElements.push_back( PII(g,p) );
      theLength += abs(p);
    } else {
      theLength -= abs( p1 );
      if( p1+p ) {
	e.second = p1+p;
	theLength += abs( p1+p );
      } else {
	theElements.pop_back( );
      }
    }
  }
}
示例#7
0
// try to walk
void trywalk(int i,int j){
    if(a>=0 and a<bar and b>=0 and b<kol and m[i][j]!='#'){
        m[i][j]='#';
        q.push(PII(a,b));
    }
}