首页 > 代码库 > BZOJ2348 [Baltic 2011]Plagiarism

BZOJ2348 [Baltic 2011]Plagiarism

BZ的水题们。。。

这道题的学名叫什么"two pointers"来着。。。就是线性扫过去啊我去、、、

PoPoQQQ称之为"《论排序算法的高效性和合理利用以及能否记得使用排序算法》"2333

 

 1 /************************************************************** 2     Problem: 2348 3     User: rausen 4     Language: C++ 5     Result: Accepted 6     Time:128 ms 7     Memory:1196 kb 8 ****************************************************************/ 9  10 #include <cstdio>11 #include <algorithm>12  13 using namespace std;14 typedef long long ll;15 typedef double lf;16 const int N = 100005;17 const lf eps = 1e-8;18  19 int n, a[N];20 ll ans;21  22 inline int read() {23     int x = 0, sgn = 1;24     char ch = getchar();25     while (ch < 0 || 9 < ch) {26         if (ch == -) sgn = -1;27         ch = getchar();28     }29     while (0 <= ch && ch <= 9) {30         x = x * 10 + ch - 0;31         ch = getchar();32     }33     return sgn * x;34 }35  36 int main() {37     int i, j;38     n = read();39     for (i = 1; i <= n; ++i)40         a[i] = read();41     sort(a + 1, a + n + 1);42     for (i = j = 1; i <= n; ++i) {43         while (a[j] + eps < (lf) a[i] * 0.9)44             ++j;45         ans += i - j;46     }47     printf("%lld\n", ans);48     return 0;49 }
View Code

 

BZOJ2348 [Baltic 2011]Plagiarism