LightOJ 1342 - Aladdin and the Magical Sticks

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <ctime>
#include <cmath>
#include <bitset>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
const int maxn = 5002;
const int SIZE = 511111;
const double eps = 1e-10;
int a[maxn], b[maxn];
int main() {
	ios::sync_with_stdio(false);
	int n, i, T, cas;
	scanf("%d",&T);
	for (cas = 1; cas <= T; ++cas) {
		scanf("%d", &n);
		for (i = 0; i < n; ++i)
			scanf("%d%d", a + i, b + i);
		double x = n, y = 0;
		for (i = n; i >= 1; --i)
			y += n * 1.0 / i;
		double delta = (y - x) / n;
		double ans = 0;
		for (i = 0; i < n; ++i) {
			ans += a[i];
			if (b[i] == 2)
				ans += a[i] * delta;
		}
		printf("Case %d: %.10f\n",cas, ans);
	}
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章