Advertisement
Best_Project

XOR_SORT

Jun 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. #include<map>
  4. #include<algorithm>
  5. #define ll long long int
  6. using namespace std;
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12.     ll n,temp = 0,dem = 0;
  13.     cin>>n;
  14.     ll *a = new ll[n];
  15.     for(long i = 0;i < n;i++) cin>>a[i];
  16.     sort(a,a+n);
  17.     for(long i = 0; i < n-1;i++)
  18.     {
  19.         if(a[i] == a[i+1]) temp++;
  20.         else
  21.         {
  22.             temp++;
  23.             //có n số nguyên ---> có n*(n-1) / 2 cặp tương ứng
  24.             dem+= (temp*(temp-1))/2;
  25.             temp = 0;
  26.         }
  27.     }
  28.     cout<<dem;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement