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;
}