Combined mathematical exercises (generated and arranged by Reverse columns)

Source: Internet
Author: User
/*************************************** * *********** Use the line segment tree to count the number of spaces, to determine where a number should be stored in the arrangement, the total time complexity is N * logn ********************************** * ******************/# include <iostream> # include <fstream> using namespace STD; # define maxn 1001 # define L (x) (x <1) # define R (x) (x <1) | 1) fstream fout ("out.txt ", IOS: Out); struct treenode {int L, R, space, P ;}; treenode node [maxn * 5]; void build_tree (int u, int L, int R) {node [u]. L = L; node [u]. R = r; node [u]. space = r-L + 1; node [u]. P = r; If (L = r) return; int mid = (L + r)> 1; build_tree (L (u), L, mid ); build_tree (R (u), Mid + 1, R);} int position (int u, int num) // determine the subscript, so that it is an empty position of num {node [u]. space --; If (node [u]. L = node [u]. r) return node [u]. l; If (Num <= node [L (u)]. space) return position (L (u), num); else return position (R (u), num-node [L (u)]. space);} void reordertopermu (int n, int * reorder, int * permu) // converts Reverse Order columns into arrays {for (INT I = 1; I <= N; I ++) {int Pos = position (1, reorder [I] + 1); permu [POS] = I ;}} int main () {int N; int reorder [maxn], permu [maxn]; while (CIN> N) // input the size of the reverse order column {build_tree (1, 1, n ); for (INT I = 1; I <= N; I ++) CIN> reorder [I]; reordertopermu (n, reorder, permu); For (INT I = 1; I <= N; I ++) fout <permu [I]; fout <Endl;} return 0 ;}

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.