标签:div while c++ pre i++ end f11 name log
思路:
搞了半天发现和绝对值无关。
http://codeforces.com/blog/entry/67081
实现:
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 int a[200005]; 5 int main() 6 { 7 int n; 8 while (cin >> n) 9 { 10 ll ans = 0; 11 for (int i = 0; i < n; i++) { cin >> a[i]; a[i] = abs(a[i]); } 12 sort(a, a + n); 13 for (int i = 0; i < n; i++) 14 { 15 ans += upper_bound(a + i + 1, a + n, 2 * a[i]) - a - i - 1; 16 } 17 cout << ans << endl; 18 } 19 return 0; 20 }
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 int a[200005]; 5 int main() 6 { 7 int n; 8 while (cin >> n) 9 { 10 ll ans = 0; 11 for (int i = 0; i < n; i++) { cin >> a[i]; a[i] = abs(a[i]); } 12 sort(a, a + n); 13 int l = 0, r = 0; 14 while (l < n) 15 { 16 while (r < n && a[r] <= 2 * a[l]) r++; 17 ans += r - l - 1; 18 l++; 19 } 20 cout << ans << endl; 21 } 22 return 0; 23 }
标签:div while c++ pre i++ end f11 name log
原文地址:https://www.cnblogs.com/wangyiming/p/10885722.html