QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#543887#27. The Battle for Wesnoth5un_xiaomivita_msgCompile Error//C++232.7kb2024-09-01 23:12:212024-09-01 23:12:21

Judging History

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

  • [2024-09-01 23:12:21]
  • 评测
  • [2024-09-01 23:12:21]
  • 提交

answer

#pragma optimize("s",on)
#include <bits/stdc++.h>

const double eps = 1e-6;

template <int T>
struct fast_io {
	char p[T], *p1, *p2, q[T], *q1, *q2;
	fast_io() {
		p1 = p2 = p, q1 = q, q2 = q + T;	
	}
	char gc() {
		return p1 == p2 && (p2 = (p1 = p) + fread(p, 1, T, stdin), p1 == p2) ? EOF : *p1++;
	}
	void pc(char ch) {
		if (q1 == q2) {
			fwrite(q, 1, T, stdout);
			q1 = q;
		}
		*q1++ = ch;
	}
	~fast_io() {
		fwrite(q, 1, q1 - q, stdout);	
	}
};
fast_io<1 << 21> io;
int read() {
	int r = 0, neg = 1;
	char ch;
	do {
		ch = io.gc();
		if (ch == '-') neg = -1;
	} while (ch < 48 || ch > 57);
	do r = r * 10 + ch - 48, ch = io.gc(); while (ch >= 48 && ch <= 57);
	return r * neg;
}

void write(int x) {
	if (x < 0) x = -x, io.pc('-');
	if (x >= 10) write(x / 10);
	io.pc(48 + x % 10);
}

void output(int x, char ch = ' ') {
	write(x);
	io.pc(ch);	
}

int main() {
	std::vector<int> useful_b;
	int m, n;
	double p;
	m = read(), p = read(), n = read();
	p /= 100;
	std::vector<int> h(n), table(m + 1);
	for (int i = 0; i < n; ++i)
		h[i] = read();
	for (int l = 1, r = 0; l <= m; l = r + 1) {
		r = m / (m / l);
		table[r] = true;
	}
	int sc = 0;
	double f = 1, g = 1;
	std::vector<std::pair<double, int>> pos(m + 1, std::make_pair(-1e18, 0));
	static double a[1000005], b[1000005];
	auto ins = [&](double val, int b, int i) {
		int t = (m / b) * i;
		pos[t] = std::max(pos[t], std::make_pair(val, b));
	};
	auto debug = [&]() {
		for (int i = 1; i <= m; ++i)
			printf("a[%d] = %.6f, b[%d] = %.6f\n", i, a[i], i, b[i]);
	};
	double z = (1 - p) / p, z0 = p / (1 - p);
	for (int i = 1; i <= m; ++i) {
		double lim = i * p;
		if (sc < lim) {
			++sc;
			double _f = f - (1 - p) * g;
			double _g = g * lim / sc;
			f = _f, g = _g;
		}
		else {
			double _f = f + g * sc * (1 - p) / (i - sc);
			double _g = g * (1 - p) * i / (i - sc);
			f = _f, g = _g;
		}
		if (table[i]) {
			a[sc] = f, b[sc] = g;
			ins(f, i, sc);
			double *pa = a + sc, *pb = b + sc;
			for (int j = sc - 1; j >= 1; --j) {
				double bj = *pb * z * (j + 1) / (i - j);
				*--pb = bj;
				double aj = *pa + *pb;
				*--pa = aj;
				if (1 - *pb > eps) {
					ins(*pa, i, j);
				}
				else if (i == m) {
					ins(1, i, j);
				}
			}
			pa = a + sc, pb = b + sc;
			for (int j = sc + 1; j <= i; ++j) {
				double bj = *pb * z0 * (i - j + 1) / j;
				double aj = *pa - *pb;
				*++pb = bj;
				*++pa = aj;
				if (*pa >= p)
					ins(*pa, i, j);
			}
		}
	}
	for (int i = m; i > 0; --i)
		pos[i] = std::max(pos[i], pos[i + 1]);
	for (int i = 0; i < n; ++i) {
		int x = 0, y = 0;
		if (h[i] > m) {
			x = y = 1;
		}
		else {
			y = pos[h[i]].second;
			x = m / y;
		}
		cout<<x<<y<<endl;
	}
}

Details

answer.code: In function ‘int main()’:
answer.code:126:17: error: ‘cout’ was not declared in this scope; did you mean ‘std::cout’?
  126 |                 cout<<x<<y<<endl;
      |                 ^~~~
      |                 std::cout
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:146,
                 from answer.code:2:
/usr/include/c++/13/iostream:63:18: note: ‘std::cout’ declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
answer.code:126:29: error: ‘endl’ was not declared in this scope; did you mean ‘std::endl’?
  126 |                 cout<<x<<y<<endl;
      |                             ^~~~
      |                             std::endl
In file included from /usr/include/c++/13/bits/unique_ptr.h:42,
                 from /usr/include/c++/13/memory:78,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:56:
/usr/include/c++/13/ostream:735:5: note: ‘std::endl’ declared here
  735 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~