QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225175#2913. Archery AccuracyPetroTarnavskyiWA 187ms5060kbC++172.3kb2023-10-24 02:46:342023-10-24 02:46:34

Judging History

你现在查看的是最新测评结果

  • [2023-10-24 02:46:34]
  • 评测
  • 测评结果:WA
  • 用时:187ms
  • 内存:5060kb
  • [2023-10-24 02:46:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

vector<db> Gauss(vector<vector<db>> a)
{
	int n = SZ(a);
	if(n == 0)
		return {};
	int m = SZ(a[0]) - 1;//number of variables
	assert(n >= m);
	
	int vars = m;
	FOR(i, 0, m)
	{
		if (a[i][i] == 0)
		{
			int row = i;
			FOR(k, i + 1, n)
			{
				if (abs(a[row][i]) < abs(a[k][i]))
					row = k;
			}
			if(row == -1)
			{
				vars--;
				continue;
			}
			swap(a[i], a[row]);
		}
		db d = 1 / a[i][i];
		FOR(k, i + 1, n)
		{
			db c = a[k][i] * d;
			FOR(j, 0, m + 1)
				a[k][j] -= c * a[i][j];
		}
	}
	FOR(i, vars, n)
		if(a[i].back() != 0)
			cout << "No solution\n";
	vector<db> x(m);
	RFOR(i, m, 0)
	{
		x[i] = a[i].back();
		FOR(j, i + 1, m)
			x[i] -= a[i][j] * x[j];
		x[i] = x[i] / a[i][i];
	}
	return x;
}

const int N = 17;

db dp[1 << N];
db r1[N + 1][N + 1];
db r2[N + 1][N + 1];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(15);
	
	int n = 17;
	//cin >> n;
	vector<db> p(n);
	FOR (i, 0, n)
		p[i] = 0.47;
		//cin >> p[i];
	VI s(n + 1, 0);
	FOR (i, 0, n)
		s[i + 1] = 100 - n + i + 1;
	
	FOR (i, 0, n)
	{
		FOR (j, 0, n)
		{
			int sz = 2 * s[i + 1];
			vector<vector<db>> a(sz, vector<db>(sz + 1));
			FOR (k, 0, sz - 1)
			{
				a[k][k] = -1;
				a[k][k + 1] = p[j];
				if (k)
				{
					a[k][k - 1] = 1 - p[j];
				}
				a[k][sz] = 0;
			}
			a[sz - 1][sz - 1] = 1;
			a[sz - 1][sz] = 1;
			auto res = Gauss(a);
			int x = (-s[i + 1]) + 1;
			r1[i][j] = res[s[i] - x];
			r2[i][j] = res[-s[i] - x];
		}
	}
	
	
	dp[0] = 1;
	FOR (i, 0, 1 << n)
	{
		int idx = __builtin_popcount(i);	
		FOR (j, 0, n)
		{
			if (i & (1 << j))
				continue;
			
			db P = r1[idx][j] * dp[i] + r2[idx][j] * (1 - dp[i]);
			if (P > dp[i | (1 << j)])
			{
				dp[i | (1 << j)] = P;
			}
		}
	}
	cout << dp[(1 << n) - 1] << '\n';
	
	cerr << db(clock()) / CLOCKS_PER_SEC << '\n';
	
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 187ms
memory: 5060kb

input:

17
0.49
0.45
0.50
0.47
0.50
0.50
0.50
0.50
0.50
0.50
0.50
0.50
0.49
0.50
0.49
0.50
0.49
15
16
17
18
19
20
26
29
86
88
89
93
95
96
97
98
100

output:

0.000006056144143

result:

wrong answer 1st numbers differ - expected: '0.4516422', found: '0.0000061', error = '0.4516362'