Example #1
0
  void lisp2tree(tree<int> &A,const string &s) {
    list<int> L;
    int EP = INT_MAX, BP=INT_MAX-1;
    const char *p = s.c_str();
    char num[100];
    while (true) {
      if (*p == '\0') break;
      else if (*p == '(') {
	L.push_back(BP);
	p++;
      } else if (*p == ')') {
	L.push_back(EP);
	p++;
      } else if (*p == ' ') p++;
      else if (*p>='0' && *p<='9') {
	char *pn=num;
	*pn=*p;
	while (*p>='0' && *p<='9') {
	  *pn++ = *p++;
	}
	*++pn='\0';
	int n = atoi(num);
	L.push_back(n);
      } else p++;
    } 
    // list<int>::iterator q = L.begin();
    // while (q!=L.end()) cout << *q++ << " ";
    // cout << endl;
    A.clear();
    list2tree(A,L,BP,EP);
  }
Example #2
0
int main(){
   scanf("%d",&T);
   for(int CA = 1; CA <= T ; CA++)
   {
	  mp.clear();
	  spt.init();
	  printf("Case %d:\n",CA);
	  scanf("%d %d",&n,&q);
	  for(int i= 1;i <= q;i ++)
	  {
		scanf("%s %d",str,&tmp);
		if(str[0] == 'T'){
			spt.insert(tmp,i);
			mp[i] = tmp ; 
	     }else if(str[0] == 'Q'){
			pair<int ,int > tt = spt.find(tmp);
			if(tt.first != -1 )
              printf("%ld\n",mp.order_of_key(tt.first) + 1);
			else{
		      printf("%ld\n",mp.size()-tt.second + tmp); 	
			}
		}else{
			if(tmp <= mp.size()){
				printf("%d\n",mp.find_by_order(tmp-1)->second);
			}else{
                printf("%d\n",spt.findrank(tmp)); 
			}
		}
	  }
   }
return 0;
}
Example #3
0
    void WeaveNet(SQcont<T> const &incont, tree<T> &outnet)
    {
      outnet.clear();
      auto top(outnet.begin());
      auto now(outnet.insert(top, *incont.cbegin()));
      for(auto c = incont.cbegin()+1;c != incont.cend();++c)
	now = outnet.append_child(now, *c);
    }
Example #4
0
    void WeaveNets(SQcont<SQcont<T> > &incont, tree<T> &outnet)
    {
      outnet.clear();
      auto top(outnet.begin());
      for(auto c = incont.begin();c != incont.end();++c){
	if(c->size()){
	  auto now(outnet.insert(top, c->at(0)));
	  for(size_t num = 1;num < c->size();++num)
	    now = outnet.append_child(now, c->at(num));
	} // End if
      } // End c
    }
Example #5
0
File: 3197.cpp Project: utoppia/HDU
int main(){
    int n,m;
    while(~scanf("%d",&n)){
        int sg=0;
        p.clear();m=0;
        for(int i=0,v;i<n;i++) {
            scanf("%d",&v);
            if(v==-1) node[m++]=i;
            else p.addadge(i,v);
        }
        for(int i=0;i<m;i++)sg ^= p.dfs(node[i]);
        printf("%s\n",sg?"YES":"NO");
    }
    return 0;
}
Example #6
0
//---:---<*>---:---<*>---:---<*>---:---<*>---:---<*>
// Wrapper
void split_down(tree<int> &T,int M,int n,int g) {
  T.clear();
  T.insert(T.begin(),M);
  split_down(T,T.begin(),n,g);
}