const int MAXN = 41000;
int ipt[MAXN];
int main()
{
LL n, r;
int kase = 1;
while (cin >> n >> r && (n && r))
{
REP(i, n)
{
int a, b;
scanf("%d.%d", &a, &b);
ipt[i] = a * 1000 + b;
}
sort(ipt, ipt + n);
FF(i, n, n + n)
ipt[i] = ipt[i - n] + 360000;
LL ans = 0, idx, x;
LL all = n * (n - 1) * (n - 2) / 6;
REP(i, n)
{
idx = lower_bound(ipt + i, ipt + n + i, ipt[i] + 180000) - ipt;
x = n + i - idx;
if (x >= 2)
ans += (x - 1) * x / 2;
}
cout << "Case " << kase++ << ": " << all - ans << endl;
}
return 0;
}Probability Through Experiments,布布扣,bubuko.com
Probability Through Experiments
原文:http://blog.csdn.net/wty__/article/details/38341127