📌  相关文章
📜  非整数距离的最大积分坐标

📅  最后修改于: 2021-05-07 18:55:56             🧑  作者: Mango

给定最大坐标x –坐标和y –坐标,我们要计算一组坐标,以使任意两点之间的距离均为非整数。选择的坐标(i,j)的范围应为0 <= i <= x和0 <= j <= y。另外,我们必须最大化设置。

例子:

Input : 4 4
Output : 0 4
         1 3
         2 2
         3 1
         4 0
Explanation : Distance between any two points
mentioned in output is not integer.

首先,我们要创建一个集合,这意味着我们的集合不能包含之前使用过的具有相同x或y的任何其他点。好吧,其背后的原因是,具有相同x坐标或y坐标的这些点将取消该坐标,从而导致它们之间的积分距离。
例如,考虑点(1,4)和(1,5),x坐标将抵消,因此,我们将获得和的距离。
其次,我们可以观察到,我们只有x + 1个不同的i坐标和y + 1个不同的j坐标。因此,集合的大小不能超过min(x,y)+1。
第三个观察结果是,我们知道对角元素为| ij | * sqrt(2)  因此,我们沿着i坐标的对角元素求值,并通过公式min(i,j)-i计算j坐标。

C++
// C++ program to find maximum integral points
// such that distances between any two is not
// integer.
#include 
using namespace std;
 
// Making set of coordinates such that
// any two points are non-integral distance apart
void printSet(int x, int y)
{
    // used to avoid duplicates in result
    set > arr;
     
    for (int i = 0; i <= min(x, y); i++) {
 
        pair pq;
        pq = make_pair(i, min(x, y) - i);
        arr.insert(pq);
    }
 
    for (auto it = arr.begin(); it != arr.end(); it++)
        cout << (*it).first << " " << (*it).second << endl;
}
 
// Driver function
int main()
{
    int x = 4, y = 4;
    printSet(x, y);
    return 0;
}


Python3
# Python3 program to find maximum integral points
# such that distances between any two is not
# integer.
 
# Making set of coordinates such that
# any two points are non-integral distance apart
def printSet(x, y):
     
    # Used to avoid duplicates in result
    arr = []
 
    for i in range(min(x, y) + 1):
        pq = [i, min(x, y) - i]
        arr.append(pq)
 
    for it in arr:
        print(it[0], it[1])
 
# Driver code
if __name__ == "__main__":
 
    x = 4
    y = 4
     
    printSet(x, y)
 
# This code is contributed by ukasp


输出:

0 4
1 3
2 2
3 1
4 0