5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

暗号化

Last updated at Posted at 2014-06-02

今回は解法が思い浮かびやすかったですね。最初に愚直方式が思いつき、次に最小値を求める軽減方式を思いつきました。HashMapを使いこなせる様になりたいのですが・・・今回の問題は適用しても計算量が増えそうな気がしたのでやめにしておきました。(やったほうがよかったのかな・・・)
問題元:SRM480 Div2 Level1
最初は愚直方式です。

public static long encrypt(int[] numbers) {
		long num = 1;
		long max = Integer.MIN_VALUE;
		for(int r = 0; r < numbers.length; r++) {
			numbers[r]++;
			for(int c = 0; c < numbers.length; c++) {
				num *= numbers[c];
			}
			numbers[r]--;
			if(num > max) max = num;
			num = 1;
		}
		return(max);
	}

次に軽減方式

public static long encrypt(int[] numbers) {
		int min = Integer.MAX_VALUE;
		int idx = 0;
		for(int r = 0; r < numbers.length; r++) {
			if(numbers[r] < min) {
				min = numbers[r];
				idx = r;
			}
		}
		numbers[idx]++;
		long ans = 1;
		for(int r = 0; r < numbers.length; r++) {
			ans *= numbers[r];
		}
		return(ans);
	}

あんまり効率が良い気がしないんですが・・・・・
俺の少ない脳細胞がもうちょっと頑張ってくれれば(笑)
・・・ソートすれば最小値簡単に導き出せるじゃないですかーーーー!!!
俺、馬鹿だぁぁぁぁぁ(泣)

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?