Struct node {long a; long B; long C; long num; int I; bool operator <(const node & T) const {return (Num> T. num) | (num = T. num & A <t. a) | (num = T. num & A = T. A & B <t. b) | (num = T. num & A = T. A & B = T. B & C <t. c) | (num = T. num & A = T. A & B = T. B & C = T. C & I <t. i) ;}} node [1005]; set <node> S;
View code
Use set to store struct, and reload the less than sign to implement fast sorting.
Pass
Node TMP; set <node >:: iterator ITER; For (INT I = sum; I> m; I --) {TMP = (* s. begin (); S. erase (TMP); res-= TMP. num; TMP. c-= 1; TMP. num = (2 * TMP. c-1) * TMP. b; S. insert (TMP );}
View code
In this way, the elements in the set are modified. Because the elements inserted into the set are immutable, the elements that you want to change are extracted first (by ITER, you can even extract the nth largest number), and then
The insert operation is wiped out to modify the elements in the set.
Use set to compare the size and shorten the time complexity