Last active
August 29, 2015 14:12
-
-
Save takanakahiko/1e891d75d614c43c64b4 to your computer and use it in GitHub Desktop.
プリクラ問題。ツイッターで見つけた。出題者に感謝。(1.4)
This file contains 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
public class PhotoBooth{ | |
public static void main(String[] args){ | |
System.out.println("【プリクラ問題】"); | |
System.out.println("n人のメンバーが"); | |
System.out.println("m人は入れるプリクラで"); | |
System.out.println("それぞれが他の各メンバーと"); | |
System.out.println("同じ写真に収まるには"); | |
System.out.println("何回の撮影が必要か\n"); | |
double n = (double)Integer.parseInt(System.console().readLine("n=")); | |
double m = (double)Integer.parseInt(System.console().readLine("m=")); | |
System.out.println(); | |
//肝心の公式だが意外とかんたんだった | |
//m次完全グラフ(各メンバーの組み合わせ)を | |
//n次完全グラフ(プリクラが一度に解消できる組み合わせ)で | |
//割れば「解消に必要な回数」がわかる。ceilは繰り上げ。 | |
int ans = (int)Math.ceil( (n*(n-1)) / (m*(m-1)) ); | |
System.out.println(ans+"回の撮影が必要である"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment