首页 > 代码库 > URAL 1079 Maximum

URAL 1079 Maximum

天天有个好心情

 1 import java.util.Scanner; 2  3 public class P1079 4 { 5     public static void main(String args[]) 6     { 7         int a[] = new int[100000]; 8         a[0] = 0; 9         a[1] = 1;10         for (int i = 2; i < 100000; i++)11             if (i % 2 == 0)12                 a[i] = a[i / 2];13             else14                 a[i] = a[i / 2] + a[i / 2 + 1];15 16         int max[] = new int[100000];17         max[0] = 0;18         for (int i = 1; i < 100000; i++)19             max[i] = Math.max(max[i - 1], a[i]);20 21         try (Scanner cin = new Scanner(System.in))22         {23             while (cin.hasNext())24             {25                 int n = cin.nextInt();26                 if (n == 0)27                     return;28                 System.out.println(max[n]);29             }30         }31     }32 }

 

URAL 1079 Maximum