Home > Back-end >  Data structure course design
Data structure course design

Time:12-02

Design program according to the order from big to small order output function f (a, b)=2 * a * a * b * b the minimum 100 function value and the corresponding values of two parameters, in which a and b are natural Numbers,
Requirements: (1) as a function of storage structure should be as far as possible to save space,
(2) the designed algorithm and time complexity of the process should be as small as possible,

CodePudding user response:

Can use the method of insertion sort side traverse a, b the result of the increasing f, save minimum 100 values
 int main () 
{
Int a, b, f [3], [100], t, I, j;
for (i=0; i<100; I++) f [2] [I]=3 * 100 * 100;
For (a=0; a<10; {+)
For (b=0; b<15. B++) {
T=a + 2 * a * b * b;
for (i=0; T> F [2] [I] & amp; & i<100; i++);//insert find insertion position
If (i<100) {
For (j=99; J> i; J -) {
F [0] [j]=f [0] [1];
F [1] [j]=f [1] [1];
F [2] [j]=f [2] [1];
}
F [0] [I]=a;
F [1] [I]=b;
F [2] [I]=t;
}
}
}
for (i=0; i<100; I++) {
Printf (" f (% d, % d)=% d \ n ", f [0] [I], f [1] [I], [2] f [I]);
}

return 0;
}
  • Related