zoukankan      html  css  js  c++  java
  • 寻找最近的点对

    // 22.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <iostream>
    #include <time.h>
    
    using namespace std;
    struct node
    {
    	int data;
    	int x;
    	int y;
    	int nx;
    	int ny;
    }node[45];
    int _tmain(int argc, _TCHAR* argv[])
    {
    	const int NUM = 10; //定义点对的数目
    	int array[2][NUM];
    	const int n = NUM*(NUM-1)/2;
    	int arrayDis[n];
    	int k = 0;
    	
    	srand(time(0));
    	//形成空间坐标
    	for (int i = 0;i<NUM;i++)
    	{
    		array[0][i]= rand()%10;
    		array[1][i]= rand()%10;
    		cout<<'('<<array[0][i]<<','<<array[1][i]<<')'<<' ';
    	}
    	//遍历各点
    
    	for (int i =1;i<NUM;i++)  //n-1次
    	{
    		for (int j =i-1;j<NUM-1;j++)//n-i次
    		{
    			
    			int distance = (array[0][j]-array[0][j+1])*(array[0][j]-array[0][j+1])+(array[1][j]-array[1][j+1])*(array[1][j]-array[1][j+1]);
    			node[k].data = distance;
    			node[k].x=i;
    			node[k].y=j;
    			node[k].nx=i;
    			node[k].ny=j+1;
    
    
    			k++;
    		}
    
    	}
    	//输出结果
    	cout<<endl;
    	for (int i = 0;i<n;i++)
    	{
    		cout<<node[i].data<<' '<<node[i].x<<' '<<node[i].y<<' '<<node[i].nx<<' '<<node[i].ny<<endl;;
    
    	}
    
    	return 0;
    }
    
    
  • 相关阅读:
    HDU 2586 How far away?
    UVAlive 5796 Hedge Mazes
    HDU 4975 A simple Gaussian elimination problem.
    Poj 1149 PIGS
    HDU 3416 Marriage Match IV
    HDU 4912 Paths on the tree
    HDU 3277 Marriage Match III
    終於記起了帳號密碼
    codeforces194a
    codeforces195c
  • 原文地址:https://www.cnblogs.com/CBDoctor/p/2623706.html
Copyright © 2011-2022 走看看