Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JavaÃæÊÔÌ⣺è³ÔÀÏÊóÎÊÌâ

ÎÊÌ⣺ÏÖÓÐn¸öÀÏÊóΧ³ÉһԲȦ£¬ÓÐһֻè´ÓÈÎÒâλÖÿªÊ¼³ÔÀÏÊó£¬Ã¿´Î¶¼¸ôÒ»¸öÀÏÊó³Ô£¬Çë¸ø³ö×îºóÒ»¸öÀÏÊóµÄ±àºÅ£¿ÌâÄ¿ÒªÇóÊÇÈθøÀÏÊóÊýn£¬Êä³öè×îºó³ÔµÄÀÏÊóµÄ±àºÅ¡£
ÎҵĽⷨ£º
1.¼òµ¥µÄ·½·¨¾ÍÊÇÄ£ÄâÕâ¸ö¹ý³Ì¡£Ê¹ÓÃÒ»¸öÊý×é´ú±íÀÏÊóÊÇ·ñ±»³Ôµô£¬Ñ­»·±éÀú¡£
2.¸Ä½øһϵķ½·¨£¬ÆäʵÕâ¸öÎÊÌâ¾ÍÊÇÒ»¸öm=2µÄԼɪ·ò»·ÎÊÌâ¡£
package com.easyProblem;
/*
* ÏÖÓÐn¸öÀÏÊóΧ³ÉһԲȦ£¬ÓÐһֻè´ÓÈÎÒâλÖÿªÊ¼³ÔÀÏÊó£¬Ã¿´Î¶¼¸ôÒ»¸öÀÏÊó³Ô£¬
* Çë¸ø³ö×îºóÒ»¸öÀÏÊóµÄ±àºÅ£¿ÌâÄ¿ÒªÇóÊÇÈθøÀÏÊóÊýn£¬Êä³öè×îºó³ÔµÄÀÏÊóµÄ±àºÅ
*/
public class CatEatMouseProblem {
private int[] m;

public static void main(String[] args) {
CatEatMouseProblem cm = new CatEatMouseProblem();
System.out.println("=======µÍЧµÄ·½·¨========");
long startTime =System.currentTimeMillis();
System.out.println(cm.easyWork(1111178));
long endTime=System.currentTimeMillis();
System.out.println("ºÄʱ£º" + (endTime-startTime));

System.out.println("=======¸Ä½øµÄ·½·¨========");
startTime =System.currentTimeMillis();
System.out.println(cm.betterWork(1111178));
endTime=System.currentTimeMillis();
System.out.println("ºÄʱ£º" + (endTime-startTime));

}
public int easyWork(int n){
m = new int[n];

int mouse = n;
int flag = 0;

m[0] = 1;
mouse--;

while(mouse>1){
flag = next(next(flag));
m[flag] = 1;
mouse--;
}
return next(flag)+1;
}

public int next(int start){
for(int i=start+1; i<start+m.length; i++){
int pos = i%(m.length);
if(m[pos]!=1) {
return pos;
}
}
return -1;
}

public int betterWork(int n){
int m = 2;
int s = 0;
for(int i=2; i<=n-1; i++) s=(s+m)%i;
return s+2;
}

=======µÍЧµÄ·½·¨========
125204
ºÄʱ£º953
=======¸Ä½øµÄ·½·¨========
125204
ºÄʱ£º31


Ïà¹ØÎĵµ£º

Êý¾Ý½á¹¹(LinkedListµÄjavaʵÏÖ)

 package day10;
import java.util.*;
public class MyLinkedList implements List
{
static class Node
{
public Object data;
public Node next;
public Node(Object data)
{
this.data=data;
}
}
private Node head;
public  MyLinkedList()
{
head=new Node(0);
}
public void add(int ind ......

java»ñÈ¡µ±Ç°Â·¾¶

java»ñÈ¡µ±Ç°Â·¾¶
 
1¡¢ÀûÓÃSystem.getProperty()º¯Êý»ñÈ¡µ±Ç°Â·¾¶£º
System.out.println(System.getProperty("user.dir"));//user.dirÖ¸¶¨Á˵±Ç°µÄ·¾¶
2¡¢Ê¹ÓÃFileÌṩµÄº¯Êý»ñÈ¡µ±Ç°Â·¾¶£º
File directory = new File("");//É趨Ϊµ±Ç°Îļþ¼Ð
try{
    System.out.println(directory.getCano ......

Java¹Ø¼ü×Öfinal¡¢staticʹÓÃ×ܽá

 
Ò»¡¢final

¡¡¸ù¾Ý³ÌÐòÉÏÏÂÎÄ»·¾³£¬Java
¹Ø¼ü×ÖfinalÓГÕâÊÇÎÞ·¨¸Ä±äµÄ”»òÕß“ÖÕ̬µÄ”º¬Ò壬Ëü¿ÉÒÔÐÞÊηdzéÏóÀà¡¢·Ç³éÏóÀà³ÉÔ±·½·¨ºÍ±äÁ¿¡£Äã¿ÉÄܳöÓÚÁ½ÖÖÀí½â¶øÐèÒª×èÖ¹¸Ä±ä£ºÉè¼Æ»òЧÂÊ¡£
finalÀ಻Äܱ»¼Ì³Ð£¬Ã»ÓÐ×ÓÀ࣬finalÀàÖеķ½·¨Ä¬ÈÏÊÇfinalµÄ¡£
final·½·¨²»Äܱ»×ÓÀàµÄ·½· ......

java JNI ³¢ÊÔ

 ¡¡¡¡Ê×ÏÈÒýÓÃһƪÎÄÕ£¬½éÉÜÒ»¸ö¼òµ¥µÄJNIµÄµ÷ÓõĹý³Ì¡£¡¡¡¡JAVAÒÔÆä¿çƽ̨µÄÌØÐÔÉîÊÜÈËÃÇϲ°®£¬¶øÓÖÕýÓÉÓÚËüµÄ¿çƽ̨µÄÄ¿µÄ£¬Ê¹µÃËüºÍ±¾µØ»úÆ÷µÄ¸÷ÖÖÄÚ²¿ÁªÏµ±äµÃºÜÉÙ£¬Ô¼ÊøÁËËüµÄ¹¦ÄÜ¡£½â¾öJAVA¶Ô±¾µØ²Ù×÷µÄÒ»ÖÖ·½·¨¾ÍÊÇJNI¡£¡¡¡¡JAVAͨ¹ýJNIµ÷Óñ¾µØ·½·¨£¬¶ø±¾µØ·½·¨ÊÇÒÔ¿âÎļþµÄÐÎʽ´æ·ÅµÄ£¨ÔÚWINDOWSƽ̨ÉÏÊÇDL ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ