HDU 3743 Frosh Week (merging sort for reverse order)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=3743

The title is to give you a sequence of n, so you can ask for reverse order. I use merge sort to ask. Merge sort has a merging process, two paragraphs before and after, when A[i] > A[j], the description a[j] than the previous paragraph ah [i],a[i+1],a[i+2]....,a[mid] , which is smaller than these, so the total reverse logarithm to add mid-i+1.

1 //File Name:HDU3743.cpp2 //Author:xiaxiaosheng3 //Created time:2015 March 09 Monday 21:54 45 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> -  - using namespacestd; - typedef __int64 INT; - Const intMAXN = 10e6+Ten; -  in intN,A[MAXN],TEMP[MAXN]; - INT ans; to voidMerger (int*a,intSintMidinte) + { -     intK =0, i = S,j = mid+1; the      while(I <= mid && J <=e) *     { $         if(A[i] <A[j])Panax Notoginsengtemp[k++] = a[i++]; -         Else the         { +Ans + = (mid-i+1); Atemp[k++] = a[j++]; the         } +     } -      while(I <= mid) temp[k++] = a[i++]; $      while(J <= e) temp[k++] = a[j++]; $      for(inti =0; I < k;++i) -A[s+i] =Temp[i]; - } the voidMergersort (int*a,intSinte) - {Wuyi     if(S <e) the     { -         intMid = (s + e)/2; Wu Mergersort (a,s,mid); -Mergersort (a,mid+1, e); About merger (A,S,MID,E); $     } -  - } - intMain () { A      while(SCANF ("%d", &n)! =EOF) +     { the          for(inti =0; I < n;++i) -scanf"%d",&a[i]); $Ans =0; theMergersort (A,0, N-1); theprintf"%i64d\n", ans); the     } the     return 0; -}
View Code

HDU 3743 Frosh Week (merging sort for reverse order)

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.