暑假集训第四场——Points Construction Problem(思维题)

Points Construction Problem


Points Construction Problem
题解:
这个题目我也不是很会,这个是一个思维题,所以我找的是一个网上的一个大佬的做法,这个方法我觉的比较精妙的地方是她构造了一个L的形状,这样把剩下的填进去就不会再增加边长,因为会互相抵消。
大佬的博客

#include<iostream>
using namespace std;
int main()
{
	int t;
	cin >> t;
	int n, m;
	while(t--)
	{
		cin >> n >> m;
		if(m > 4*n || (m&1) || (m*m < 16*n)) 
		{
			cout << "No" << endl;
			continue;
		}
		else if(m > 2 * n + 2)
		{
			cout << "Yes" << endl;
			int x = (m-(2*n+2))/2;
			int y = n - x;
			for(int i = 1; i <= x; i++)
			{
				cout << "1 " << 2*i <<  endl;
			}
			for(int i = 1; i <= y; i++ )
			{
				cout << "3 " << i <<  endl;		
			}
			
		}
		else
		{
			cout << "Yes" << endl;
			int x=m/4;
			int y=m/2-x;
			for(int i = 1; i <= x; i++)
			{
				cout << i << " 1" << endl;
			}
			for(int i = 2; i <= y; i++)
			{
				cout << "1 " << i << endl;
			}
			
			int sum = n - (x+y-1);
			int cnt = 0;
			int flag = 0;
			for(int i = 2; i <= x; i++)
			{
				for(int z = 2; z <= y; z++)
				{
					if(cnt >= sum)
					{
						flag = 1;
						break;
					}
					cout << i << ' ' << z << endl;
					cnt++;
				}
				if(flag)
					break;
			}
				
		}
	}
	return 0;	
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值