|
kasama |
|
こんにちは。ツヨシ君、マサヒコ君、サトルさん、ヤオミン君の4人だけが前方を見ることができる並び方と勘違いしていました^o^。プログラムを作成して調べると、
1人だけが前方を見ることができるのは120何通り 2人だけが前方を見ることができるのは274何通り 3人だけが前方を見ることができるのは225何通り 4人だけが前方を見ることができるのは85何通り 5人だけが前方を見ることができるのは15何通り 6人だけが前方を見ることができるのは1何通り となりました。 import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Question353 { List heightList = new ArrayList(); public Question353() { for (int height = 120; height <= 220; height += 20) heightList.add(new Integer(height)); } public int getCount(int n) { int count = 0; List permuList = new Permutation(heightList).getList(); for (Iterator iter = permuList.iterator(); iter.hasNext(); ) { List list = (List) iter.next(); int m = 0; for (int i = 0; i < list.size(); ++i) if (check(list, i)) ++m; if (m == n) ++count; } return count; } private boolean check(List list, int index) { Integer height = (Integer) list.get(index); for (int i = 0; i < index; ++i) { Integer othter = (Integer) list.get(i); if (othter.intValue() > height.intValue()) return false; } return true; } public static void main(String args[]) { Question353 question = new Question353(); for (int i = 1; i <= 6; ++i) System.out.println(i + "人だけが前方を見ることができるのは" + question.getCount(i) + "何通り"); } } |
|
和歌山
5月15日(木) 1:48:27
MAIL:kasama@s34.co.jp 18623 |