예제 #1
0
void burn() {
	leaf top;

	// while(true) {

		top=Q.min();

		std::cout<<"____"<<top<<"____\n";

		if(top.i==size-1 && top.j==size-1){
			std::cout<<top.minsum<<std::endl;
			return;
		}

		array[top.i][top.j].visited=true;
		top.findneighbours();

		int z;

		Q.removemin();
		// std::cout<<"\nQueue...\n";
		// Q.print();
		// std::cout<<"############\n\n";
		for(z=0;z<top.neighbours.size();++z) {
			top.neighbours[z].add(top.minsum);
			// std::cout<<"    "<<top.neighbours[z]<<'\n';
			Q.insert(top.neighbours[z]);
		}


	// int i, j;

	// for(i=0;i<5;++i){
	// 	for(j=0;j<5;++j){
	// 		std::cout<<array[i][j].visited<<" ";
	// 	}
	// 	std::cout<<"\n";
	// }

	// std::cin.get();
	burn();
	// }
}
void conduct() {
  scanf("%d%d", &n, &q);
  cur = n = ans = 0;
  lft.avl_init(); rit.avl_init();
  pref[0] = &rit; pref[1] = &lft;
  while (q--) {
    int cmd;
    scanf("%d", &cmd);
    if (cmd) {
      int id1 = pref[0]->tree[pref[0]->avl_head()].id;
      int id2 = pref[1]->tree[pref[1]->avl_head()].id;
      if (!pref[0]->empty() && (abs(cur-val[id1]) <= abs(cur-val[id2]) || pref[1]->empty())) {
        ans += abs(cur-val[id1]);
        cur = val[id1];
        pref[0]->avl_remove(id1);
      }
      else if (!pref[1]->empty()) {
        ans += abs(cur-val[id2]);
        cur = val[id2];
        pref[1]->avl_remove(id2);
        avl_tree* tmp = pref[0];
        pref[0] = pref[1];
        pref[1] = tmp;
      }
    }
    else {
      int pos;
      scanf("%d", &pos);
      if (n == N-1) while (1);
      val[++n] = pos;
      if (val[n] == cur) pref[0]->avl_insert(n);
      else if (val[n] < cur) lft.avl_insert(n);
      else rit.avl_insert(n);
    }
  }
  cout << ans << endl;
}
예제 #3
0
int main() {
	int i,j;

#include "83.3.txt"



	for(int i=0;i<size;++i) {
		for(j=0;j<size;++j) {
			array[i][j].set(i,j);
		}
	}

	array[0][0].minsum=numbers[0][0];
	Q.insert(array[0][0]);

	burn();
}
예제 #4
0
 V& operator [](K key) {
   typename avl_tree<node>::node *n =
     tree.find(node(key, V(0)));
   if (!n) n = tree.insert(node(key, V(0)));
   return n->item.value; } };