Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int solve() {
  8.     int n;
  9.     cin >> n;
  10.     vector<int> v(n);
  11.  
  12.     for (int i = 0; i < n; ++i)
  13.         cin >> v[i];
  14.  
  15.     sort(v.begin(), v.end());
  16.  
  17.     int res = 0;
  18.     for (int i = 0; i < v.size(); ++i) {
  19.         if (i != 0 && v[i-1] == v[i]) continue;
  20.         for (int j = i+1; j < v.size(); ++j) {
  21.             if (v[j-1] == v[j] && i + 1 != j) continue;
  22.             for (int k = j+1; k < v.size(); ++k) {
  23.                 if (v[k-1] == v[k] && j + 1 != k) continue;
  24.                 if (v[k] < v[i] + v[j]) res++;
  25.             }
  26.         }
  27.     }
  28.  
  29.     return res;
  30. }
  31.  
  32. int main() {
  33.     int t;
  34.     cin >> t;
  35.     for (int i = 0; i < t; ++i)
  36.     {
  37.         cout << "Case #" << i+1 << ": " << solve() << endl;
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement