CF1166C A Tale of Two Lands
Posted 王宜鸣
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF1166C A Tale of Two Lands相关的知识,希望对你有一定的参考价值。
思路:
搞了半天发现和绝对值无关。
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 }
以上是关于CF1166C A Tale of Two Lands的主要内容,如果未能解决你的问题,请参考以下文章
13 JSON-RPC: a tale of interfaces
CF1005C Summarize to the Power of Two 暴力 map
CF1207A There Are Two Types Of Burgers