ÂùÁ¦·¨ºÍ·ÖÖη¨ Çó×î½ü¶ÔÎÊÌâ——Java ʵÏÖ
Éèp1=(x1, y1), p2=(x2, y2), …, pn=(xn, yn)ÊÇÆ½ÃæÉÏn¸öµã¹¹³ÉµÄ¼¯ºÏS£¬Éè¼ÆËã·¨ÕÒ³ö¼¯ºÏSÖоàÀë×î½üµÄµã¶Ô¡£
ÂùÁ¦Ëã·¨ÃèÊö£º
int ClosestPoints(int n, int x[ ], int y[ ], int &index1, int &index2)
{
minDist=+∞;
for (i=1; i<n; i++)
for (j=i+1; j<=n; j++)
{
d=(x[i]-x[j])* (x[i]-x[j])+(y[i]-y[j])* (y[i]-y[j]);
if (d<minDist) {
minDist=d;
index1=i;
index2=j;
}
}
return minDist;
}
ClosestPair1.java //ÂùÁ¦Ëã·¨
import java.util.*;
public class ClosestPair1
{
public static void main(String[] args)
{
/**
*ÊäÈëÐèÒª±È½ÏµÄµãµÄ¶ÔÊý´æÔÚ±äÁ¿nÖÐ
*/
Scanner in=new Scanner(System.in);
System.out.println("How many pairs of points to compare?(ÓжàÉÙ¶ÔµãÐèÒª±È½Ï?)");
int n=in.nextInt();
int[] x=new int[n];
int[] y=new int[n];
/**
*ÊäÈëÕâЩµãµÄºá×ø±êºÍ×Ý×ø±ê·Ö±ð´æ´¢ÔÚx[n]ºÍy[n]
*/
System.out.println("Please enter these points,X-coordinate(ÇëÊäÈëÕâЩµã,ºá×ø±ê):");
for(int i=0;i<n;i++)
{
x[i]=in.nextInt();
}
System.out.println("Please enter
Ïà¹ØÎĵµ£º
ÀàµÄ³õʼ»¯ºÍ¶ÔÏó³õʼ»¯ÊÇ JVM ¹ÜÀíµÄÀàÐÍÉúÃüÖÜÆÚÖзdz£ÖØÒªµÄÁ½¸ö»·½Ú£¬Google ÁËÒ»±éÍøÂ磬ÓйØÀà×°ÔØ»úÖÆµÄÎÄÕµ¹ÊDz»ÉÙ£¬È»¶øÀà³õʼ»¯ºÍ¶ÔÏó³õʼ»¯µÄÎÄÕ²¢²»¶à£¬ÌرðÊÇ´Ó×Ö½ÚÂëºÍ JVM ²ã´ÎÀ´·ÖÎöµÄÎÄÕ¸üÊÇÏÊÓÐËù¼û¡£
±¾ÎÄÖ÷Òª¶ÔÀàºÍ¶ÔÏó³õʼ»¯È«¹ý³Ì½øÐзÖÎö£¬Í¨¹ýÒ»¸öʵ¼ÊÎÊÌâÒýÈ룬½«Ô´´úÂëת»»³É JVM ×Ö½ÚÂëºó£¬ ......
¡¾IT168 ¼¼ÊõÎĵµ¡¿Ïß³Ìͬ²½£º
¡¡¡¡ÓÉÓÚͬһ½ø³ÌµÄ¶à¸öÏ̹߳²ÏíͬһƬ´æ´¢¿Õ¼ä£¬ÔÚ´øÀ´·½±ãµÄͬʱ£¬Ò²´øÀ´ÁË·ÃÎʳåÍ»Õâ¸öÑÏÖØµÄÎÊÌâ¡£JavaÓïÑÔÌṩÁËרÃÅ»úÖÆÒÔ½â¾öÕâÖÖ³åÍ»£¬ÓÐЧ±ÜÃâÁËͬһ¸öÊý¾Ý¶ÔÏó±»¶à¸öÏß³Ìͬʱ·ÃÎÊ¡£
¡¡¡¡ÐèÒªÃ÷È·µÄ¼¸¸öÎÊÌ⣺
¡¡¡¡1)synchronized¹Ø¼ü×Ö¿ÉÒÔ×÷Ϊº¯ÊýµÄÐÞÊηû£¬Ò²¿É×÷Ϊº¯ÊýÄÚµÄÓï ......
1£©DOM£¨JAXP Crimson½âÎöÆ÷£©
DOMÊÇÓÃÓëÆ½Ì¨ºÍÓïÑÔÎ޹صķ½Ê½±íʾXMLÎĵµµÄ¹Ù·½W3C±ê×¼¡£DOMÊÇÒÔ²ã´Î½á¹¹×éÖ¯µÄ½Úµã»òÐÅϢƬ¶ÏµÄ¼¯ºÏ¡£Õâ¸ö²ã´Î½á¹¹ÔÊÐí¿ª·¢ÈËÔ±ÔÚÊ÷ÖÐѰÕÒÌØ¶¨ÐÅÏ¢¡£·ÖÎö¸Ã½á¹¹Í¨³£ÐèÒª¼ÓÔØÕû¸öÎĵµºÍ¹¹Ôì²ã´Î½á¹¹£¬È»ºó²ÅÄÜ×öÈκι¤×÷¡£ÓÉÓÚËüÊÇ»ùÓÚÐÅÏ¢²ã´ÎµÄ£¬Òò¶ ......
ÖйúJavaÅàѵ£¬ÓÈÆäÊDZ±¾©µÄJavaËùν¸ß¶ËÅàѵ£¬ÖÁÉÙÒѾ»ðÁË5ÄêÒÔÉÏÁË£¬×î½üÓÐһЩÏë·¨ºÍ´ó¼Ò·ÖÏíһϡ£
ÏÖÔڱȽÏÓÐÃûµÄJavaÅàѵÓÐ ´ïÄÚ£¬¶«·½±ê×¼£¬ÉÐѧÌ㬴«ÖDz©¿Í£¬Èü¶û¿´ï£¬»¹ÓÐÀ¶µãµÈµÈ°ÉÆäËûÃûÆø²»Ôõô´óÁË£¬¶ÔÁË»¹Óб±´óÇàÄñ ¡£
×îÔçÖªµÀµÄÊDZ±´óÇàÄñ£¬ÉÏ´óѧ¾ÍÖªµÀÕâ¸öÁË ......
1. Ò»¸öjavaÔ´ÎļþÖ»ÓÐÒ»¸öpublicÀàÇÒÀàÃûÓëÎļþÃûÒ»Ö¡£×¢£ºÒ»¸ö¿ÉÔËÐеÄjavaÓ¦ÓóÌÐòÓ¦ÓÐÒ»¸ömain·½·¨£¬ÇÒ¸ñʽ¹Ì¶¨£¬µ«²»Ò»¶¨ÔÚpublicÀàÖС£
2. packageÓï¾äÖ»ÄÜÓÐÒ»¸öÇÒ·ÅÔÚ³ÌÐòµÄµÚÒ»ÐС£
3. ÕûÊýÔÚÄÚ´æÖÐʽ°´ÕÕÆä²¹ÂëÀ´´æ´¢µÄ£¬ÕýÊýµÄ²¹Âë=ÔÂ룬¸ºÊýµÄ²¹Âë=ÔÂëÈ¡·´¼Ó1 £¬charÎÞ·ûºÅ루0~65535£©
4. Ç¿ÖÆ ......