くだらないコード

2049 ワード

import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;



public class ComputeThead {

	public static void main(String[] args) {
		int maxThreadNumber = 50;
		int sleep = 5;
		int requestAvgTime = 2;
		int p = 2;
		int maxRequestNumber = 360;
		int round = 1;
		HashMap<Integer, Integer> result = new HashMap<Integer, Integer>();
		Random random = new Random();
		for (int x = 1; x <= (maxRequestNumber * round); x++) {
			int requestTime = random.nextInt(requestAvgTime);
			int r = p * maxThreadNumber + (sleep + requestTime) * x - requestTime;
			int count = 1;
			for (int n = 1; n < maxThreadNumber; n++) {
				for (int xn = 1; xn <= (maxRequestNumber * round); xn++) {
					int nRequestTime = random.nextInt(requestAvgTime);
					int nr = p * (n) + (sleep + nRequestTime) * xn - nRequestTime;
					if (nr <= (r + requestTime) && nr >= r) {
						count++;
						break;
					}
				}
			}
			result.put(x, new Integer(count));
		}
		
		HashMap<Integer, Integer> sortedResult = new HashMap<Integer, Integer>();
		Integer key = 0;
		for (Iterator<Integer> it = result.keySet().iterator(); it.hasNext();) {
			Integer i = it.next();
			if (key == 0) {
				key = i;
			}
			if (result.get(key) <= result.get(i)) {
				//System.out.println("--------" + key+ ", "+ i);
				if (result.get(key) + key > result.get(i).intValue() + i) {
					key = i;
				} 
			}
		}
		
		System.out.println(key + ", " + result.get(key) + ", " + result.get(2));
		int percent = 0;
		for (int i = 0; i < result.get(key) * 2; i++) {
			percent = percent + random.nextInt(200);
		}
		
		System.out.println(percent / 100);
	}

}