枚举 codeforces 452B

// 最优解肯定包含两个顶点,所以枚举其他两个点即可,而且这两个点一定是在相对的边上
#include 
#include 
#include 
#include 
#include 
#define ll long long
using namespace std;
const double eps=1e-6;
struct node
{
    ll x, y;
} p[4], res[4];
int vis[4];
int n, m;
ll ans;
int choose[4];
ll cal()
{
	ll ret = 0;
	for (int i = 0; i < 3; ++i)
	{
		ll cur = (p[choose[i + 1]].x - p[choose[i]].x) * (p[choose[i + 1]].x - p[choose[i]].x);
		cur += (p[choose[i + 1]].y - p[choose[i]].y) * (p[choose[i + 1]].y - p[choose[i]].y);
		ret += cur;
	}
	return ret;
}
void dfs(int dep)
{
	if (dep == 4) 
	{
		ll cur = cal();
		//for (int i = 0; i < 4; ++i) cout << choose[i] << " ";
		//cout << endl;
		//cout << "ans = " << ans << " cur = " << cur << endl;
		if (ans < cur)
		{
			ans = cur;
			for (int i = 0; i < 4; ++i) res[i] = p[choose[i]];
		}
		return;
	}
	for (int i = 0; i < 4; ++i)
	{
		if (vis[i]) continue;
		vis[i] = 1;
		choose[dep] = i;
		dfs(dep + 1);
		vis[i] = 0;
	}
}
int main()
{
	//freopen("in.txt", "r", stdin);
    while (cin >> n >> m)
    {
        if (n > 0 && m > 0)
        {
			memset(vis, 0, sizeof(vis));
            p[2].x = p[0].x = p[0].y = 0;
			p[1].x = p[3].x = n;
			p[3].y = m;
			ans = 0;
			for (int i = 0; i < m; ++i)
			{
				p[1].y = i;
				for (int j = 1; j <= m; ++j)
				{
					p[2].y = j;
					dfs(0);
				}
			}
			p[1].y = 0;
			p[2].y = m;
			for (int i = 1; i <= n; ++i)
			{
				p[1].x = i;
				for (int j = 0; j < n; ++j)
				{
					p[2].x = j;
					dfs(0);
				}
			}
			//cout << "ans = " << ans << endl;
			for (int i = 0; i < 4; ++i) cout << res[i].x << " " << res[i].y <


你可能感兴趣的:(ACM)