QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#417281#8669. 正方形计数RomeoCompile Error//C++141.6kb2024-05-22 17:02:492024-05-22 17:02:49

Judging History

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

  • [2024-05-22 17:02:49]
  • 评测
  • [2024-05-22 17:02:49]
  • 提交

answer

#include <iostream>
#include <algorithm>
const int N = 8;
const int INF = 0x3f3f3f3f;
int read() {int x; return scanf("%d", &x), x;}
int n, m;
int _x[N + 5], _y[N + 5];
struct function
{
	int a, b, c; // ax + by + c >= 0
} t[N + 5], p[N + 5];
int get(int x)
{
//	printf("******%d******\n", x);
	int l = -INF, r = INF;
	for (int i = 1; i <= n; i ++ )
	{
		int a = p[i].a, b = p[i].b, c = p[i].c;
//		printf("%d %d %d\n", a, b, c);
		if (b == 0) if (a * x + c < 0) return 0;
		if (b > 0) l = std :: max(l, (int)std :: ceil(1.0 * ( - a * x - c) / b));
		if (b < 0) r = std :: min(r, (int)std :: floor(1.0 * (a * x + c) / (-b)));
		if (l > r) return 0; 
	}
//	printf("%d %d\n", l, r);
	return r - l + 1;
}
int main()
{
	n = read();
	for (int i = 1; i <= n; i ++ ) _x[i] = read(), _y[i] = read(), m = std :: max(m, std :: max(_x[i], _y[i]));
	for (int i = 1; i <= n; i ++ )
	{
		int x1 = _x[i], y1 = _y[i], x2 = _x[i % n + 1], y2 = _y[i % n + 1];
		if (x1 == x2)
		{
			if (y1 < y2) t[i] = /* */ {1, 0, -x1};
			else t[i] = /* */ {-1, 0, x1};
		}
		else t[i] = /* */ {y2 - y1, x1 - x2, x2 * y1 - x1 * y2};
	}
	for (int i = 1; i <= n; i ++ ) p[i] = t[i];
	int res = 0;
	for (int a = 1; a <= m; a ++ )
	{
		for (int b = 0; b <= m; b ++ )
		{
//			int a = 1, b = 1;
			for (int i = 1; i <= n; i ++ ) p[i].c = t[i].c - std :: max({t[i].a * (0) + t[i].b * (0), t[i].a * ( - a) + t[i].b * ( - b), t[i].a * (b - a) + t[i].b * ( - a - b), t[i].a * (b) + t[i].b * ( - a)});
			for (int i = 0; i <= m; i ++ ) res += get(i);
		}
	}
	printf("%d", res);
	return 0;
}

/*
4
0 2
2 2
2 0
0 0

6
*/

Details

answer.code: In function ‘int get(int)’:
answer.code:21:58: error: ‘ceil’ is not a member of ‘std’
   21 |                 if (b > 0) l = std :: max(l, (int)std :: ceil(1.0 * ( - a * x - c) / b));
      |                                                          ^~~~
answer.code:22:58: error: ‘floor’ is not a member of ‘std’
   22 |                 if (b < 0) r = std :: min(r, (int)std :: floor(1.0 * (a * x + c) / (-b)));
      |                                                          ^~~~~
answer.code: In function ‘int read()’:
answer.code:5:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 | int read() {int x; return scanf("%d", &x), x;}
      |                           ~~~~~^~~~~~~~~~