`
auauau
  • 浏览: 172044 次
社区版块
存档分类
最新评论

记忆算法

阅读更多
package test;

public class Word {

	private String word;
	private int level;
	private int no;
	
	public String getWord() {
		return word;
	}
	public void setWord(String word) {
		this.word = word;
	}
	public int getLevel() {
		return level;
	}
	public void setLevel(int level) {
		this.level = level;
	}
	public int getNo() {
		return no;
	}
	public void setNo(int no) {
		this.no = no;
	}
	
	
}

package ccj;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Vector;

import test.Word;

public class Ccj {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Map<Integer,Integer> map = new HashMap<Integer,Integer>();
		map.put(1, 2);
		map.put(2, 4);
		map.put(3, 6);
		map.put(4, 12);
		map.put(5, 24);
		map.put(6, 40);
		
		List<Word> list1 = new Vector<Word>();
		List<Word> list2 = new Vector<Word>();
		
		for(int i=65;i<91;i++){
			Word w = new Word();
			w.setWord((char)i+"");
			list1.add(w);
		}
		

		int i=0;
		int ii=0;
		while(i<list1.size() || list2.size()>0){
			//old
			boolean study = false;
			for(int j=0;j<list2.size();j++){
				Word w = list2.get(j);
				if(w.getLevel()<7){ //需要study
					int num = map.get(w.getLevel());
					if((w.getNo()+num)<ii){
						w.setNo(ii);
						study(w);		
						ii++;
						study = true;
					}					
				}else{
					list2.remove(j);
				}
			}
		
			if(list2.size()<10){				
				//new
				if(i<list1.size()){
					Word w = list1.get(i);
					w.setNo(ii);
					study(w);
					ii++;
					if(w.getLevel()==1){
						list2.add(w);
					}
				}
				i++;
			}
			
			if(!study){
				ii++;
			}

		}
		
	}
	
	public static void study(Word word){		
		Random r = new Random();
		int value = r.nextInt(2);
//		System.out.println(value);
//		System.out.println(word.getLevel()+"@@@");
		if(value==0){ //重学
			word.setLevel(1);
			System.out.println(word.getWord()+"-"+"["+word.getLevel()+"]");
		}else{
			if(word.getLevel()==0){//第一次
				word.setLevel(7);
			}else{
				word.setLevel(word.getLevel()+1);
			}
			System.out.println(word.getWord()+"+"+"["+word.getLevel()+"]");
		}
	}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics