Home > Back-end >  To a big help me and explain the procedures, I don't understand
To a big help me and explain the procedures, I don't understand

Time:12-02

# include

Typedef struct
{
Int a, b, r;
} Situation;

Situation array [65536].
Int current_size=0;

Int f (int a, int b) {
Return a + 2 * a * b * b;
}

Void heapify (int position)
{
Situation TMP.
Int left position + 1=2 * and right position + 2=2 *;
Int min=position;
If (left {
Min=left;
}
If (right {
Min=right;
}
If (min!=position)
{
TMP=array [position];
Array [position]=array (min),
Array (min)=TMP;
Heapify (min).
}
}

Void insert_heap (int a, int b)
{
Int the current, the parent;
Situation TMP.
Array [current_size] a=a;
Array [current_size]. B=b;
Array [current_size]. R=f (a, b);

The current=current_size;
The parent=(current - 1)/2;

While (the parent>=0 && array [r]. Parent r> array [current]. R)
{
TMP=array (the parent),
Array [parent]=array [current];
Array [current]=TMP;
The current=parent;
The parent=(current - 1)/2;
}

+ + current_size;
}

Situation heap_pop ()
{
Situation answer=array [0];
Array [0]=array [] current_size - 1;
- current_size;
Heapify (0);
Return answer;
}

Int main ()
{
Situation sit;
Situation answer [100].
Int answer_size=0;
Int I, ok;
Insert_heap (0, 0);
While (answer_size <100)
{
Sit=heap_pop ();
Ok=0;
for (i=0; I {
If (sit) a==answer [I] a && sit.==b answer [I]. B)
{
Ok=1;
}
}
if (! Ok)
{
If (answer_size==0 | | answer [answer_size - 1]. R!=sit. R)
{
Answer [answer_size + +]=sit;
}
Insert_heap (sit) a, sit. B + 1);
Insert_heap (sit. A + 1, sit. B);
}
}
For (I=99; i>=0; - I)
{
Printf (f=% d ", a=% d, b=% d \ n ", answer [I]. Am j r, answer [I] a, answer [I]. B);
}

return 0;
}
  • Related