a044. 空間切割
參考影片:(DM10-20131118-03) 平面分割空間
沒有用lineCut和spaceCut是因為會超時TLE(Time Limit Exceed)
程式碼如下:
- /* a044. 空間切割
- *
- * 2020/3/5
- */
- import java.util.Scanner;
- public class Pa044{
- public static void main(String[] args){
- Scanner scanner = new Scanner(System.in);
- while(scanner.hasNext()){
- System.out.println(spaceCutSuper(scanner.nextInt()));
- }
- }
- public static int lineCut(int n){
- return n == 0? 1: lineCut(n - 1) + n;
- }
- public static int spaceCut(int n){
- return n == 0? 1: spaceCut(n - 1) + lineCut(n - 1);
- }
- public static int spaceCutSuper(int n){
- return (n * n * n + 5 * n + 6 ) / 6;
- }
- }
沒有留言:
張貼留言