Created
October 16, 2013 02:10
-
-
Save cocodrips/7001596 to your computer and use it in GitHub Desktop.
SRM div2 500 当初の実装(タイムオーバー) 最終版:https://gist.github.com/cocodrips/7001559
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashSet; | |
public class AstronomicalRecordsEasyBaka { | |
public int minimalPlanets(int[] A, int[] B) { | |
int min = A.length + B.length - 1; | |
for (int a = 1; a <= 1000; a++) { | |
for (int b = 1; b <= 1000; b++) { | |
if (a % 2 == 0 && b % 2 == 0) { | |
continue; | |
} | |
HashSet<Integer> set = new HashSet<Integer>(); | |
for (int ai = 0; ai < A.length; ai++) { | |
set.add(A[ai] * a); | |
} | |
for (int bi = 0; bi < B.length; bi++) { | |
if (min <= set.size()) { | |
break; | |
} | |
set.add(B[bi] * b); | |
} | |
min = set.size(); | |
} | |
} | |
return min; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment