Use set to compare the size and shorten the time complexity

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.