示例#1
0
/** @brief El progrma utilizara las clases Especie, Area, Cjt_especies y Cjt_areas
*/
int main() {
	Cjt_especies c;
	c.leer_cjt_especies();	
	int R = readint();
	int n = c.num_especies();
    Cjt_areas E(R,n) ;
	E.leer_cjt_areas();
    int accion = readint();
    while (accion != -6) {
		if (accion == -1) {
			E.lucha_especies(c);
		}
		else if (accion == -2) {
			int t = readint();
			int r = readint();
			int e = readint();
			int h = readint();
			int g = readint();
			Arbre<int> b = E.arbol_areas();
			if (t == 1) {
				if (r != b.arrel()) {
						Arbre <int> a1;
						Arbre <int> a2;
						b.fills(a1, a2);
					while (a1.arrel() != r and a2.arrel() != r) {
						Arbre <int> a3;
						a1 = a3;
						a2 = a3;
						b.fills(a1, a2);
					}
					if (a1.arrel() == r) b = a1;
					else b = a2;
				}	
				E.anade_especimenes(r, e, h*(-1));	
				E.migracion_a(b, r, e, h, g);
			}
			else {
				pair<bool, int> x;
				x = E.migracion_b(b, r, e, h, g);
			}
		}

		else if (accion == -3) {
			int m = readint();
			int e = readint();
			int r = readint();
			E.anade_especimenes(r, e, m);
		}
		else if (accion == -4) {
			int e = readint();
			int n = readint();
			c.cambia_preferencias(e, n);
		}
		else if (accion == -5) {
			E.escribir_cjt_areas();
		}
		cin >> accion;
    }
}
示例#2
0
int Organigrama::assign_offi_less_level(Arbre<int> &a, Agenda &agenda, int day, int& level_aux, int level, bool &found, int& depth)
{
    int id;
    if (level_aux <= level and not a.es_buit()) {
        int root = a.arrel();
        int id_cita;
        agenda.consultar_cita(root, day, id_cita);
        if (id_cita == 0) {
            found = true;
            depth = 0;
            id = root;
        }
        else {
            ++level_aux;
            Arbre<int> a1, a2;
            a.fills(a1, a2);
            int depth1, depth2;
            bool found1, found2;
            int id_1, id_2;
            id_1 = assign_offi_less_level(a1, agenda, day, level_aux, level, found1, depth1);
            id_2 = assign_offi_less_level(a2, agenda, day, level_aux, level, found2, depth2);

            if (found1 and found2) {
                depth1 = depth1 + 1;
                depth2 = depth2 + 1;
                if (depth1 <= depth2) {
                    depth = depth1;
                    id = id_1;
                }
                else {
                    depth = depth2;
                    id = id_2;
                }
            }

            else if (found1) {
                depth = depth1 + 1;
                id = id_1;
            }
            else if (found2) {
                depth = depth2 + 1;
                id = id_2;
            }
            found = found1 or found2;
            --level_aux;
            a.plantar(root, a1, a2);
        }
    }
    else found = false;
    if (found) return id;
    else return -1;
}
示例#3
0
文件: ArbIOint.hpp 项目: Outer2g/PRO2
void escriure_arbre_int( Arbre<int> &a) {
  if (not a.es_buit()) { 
    Arbre<int> a1;
    Arbre<int> a2;
    int x = a.arrel();
    a.fills(a1,a2);
    escriure_arbre_int(a1); 
    cout << " " << x;
    escriure_arbre_int(a2); 
    a.plantar(x,a1,a2);
  }
 
}