隨筆-28  評論-51  文章-10  trackbacks-0
          //pku1006 源代碼分析
          //注釋掉的是第一次寫的,用的是窮舉的方法,輸出結//果都正確,但是time limited,想想也是哦,這么
          //做,三次循環,不超時才怪啊,
          //現在的代碼采用逆推方法,一個循環,快多了:)
          //總結:寫代碼,首要的是解題思路要對頭,要高效,//然后有可能才考慮代碼優化,性能提高的問題!!!//切記!!
          package com.pku;
          import java.io.*;
          import java.util.*;


          public class Pku1006 {

              
          /**
               * 
          @param args
               
          */
                  
          public static void main(String[] args) {
                  
          // TODO Auto-generated method stub
                  Scanner cin = new Scanner(new BufferedInputStream(System.in));        
                  
          int p = 0;
                  
          int e = 0;
                  
          int i = 0;
                  
          int d = 0;
                  
          int n = 0;
                  
          int t = 1;
                  
          while(cin.hasNext())
                  {
                      p 
          = cin.nextInt();
                      e 
          = cin.nextInt();
                      i 
          = cin.nextInt();
                      d 
          = cin.nextInt();
                      
          if(p == -1break;
                      
          else
                      {
                          System.out.print(
          "Case"+ ' '+ t + ": the next triple peak occurs in ");
                          
          for(n = d+1; n<=21253 + d;n++)
                          {
                              
          if(Math.abs(n-p)%23==0&&Math.abs(n-e)%28==0&&Math.abs(n-i)%33==0
                              {
                                  System.out.println((n
          -d)+ " days.");
                                  
          break;
                              }
                          }
                      }
                      t
          ++;
                  }
              }
          }

          //有的時候是思想方法不多,才使程序通不過,只有思想方法,解題方法正確以后,才考慮程序的優化問題,才有意義!
          //    自已編寫的可以得出正確結果,但是TIME LIMITED~:(
          //    int  nextPeak(int p, int e, int i,int d)
          //    {
          //        int x = 0;
          //        for(x = 1; x < (21252+365)/23; x++)
          //            for(int y=1; y < (21252+365)/28; y++)
          //                for(int z=1; z < ((21252+365)/33); z++)
          //                {
          //                    if((p+23*x) == (e + 28*y )&& (e + 28*y) == (i + 33*z))
          //                    {
          //                        if( p + 23*x <= d)
          //                            return nextPeak(d + 23*x ,d + 23*x ,d + 23*x ,d);
          //                        else return p +23*x -d;
          //                    }
          //                }
          //        return p +23*x -d;
          //    }
          //    public static void main(String[] args) {
          //        // TODO Auto-generated method stub
          //        Scanner cin = new Scanner(new BufferedInputStream(System.in));
          //        Pku1006 pku1006 = new Pku1006();
          //        int p = 0;
          //        int e = 0;
          //        int i = 0;
          //        int d = 0;
          //        int days = 0;
          //        int k = 1;
          //        int first = 0;
          //        while(cin.hasNext())
          //        {
          //            if( (first = cin.nextInt())== -1)
          //            {
          //                if(cin.nextInt()== -1&&cin.nextInt()== -1&&cin.nextInt()== -1)
          //                {
          //
          //                    return;
          //                }
          //            }
          //            else{
          //                p = first;
          //                e = cin.nextInt();
          //                i = cin.nextInt();
          //                d = cin.nextInt();
          //                days = pku1006.nextPeak(p,e,i,d);
          //                System.out.println("Case "+k+": the next triple peak occurs in "+days+" days.");
          //                k++;
          //            }
          //        }
          //        
          //    }



          Pku1006
          posted on 2007-11-01 10:41 fullfocus 閱讀(779) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 璧山县| 河源市| 全州县| 盐边县| 荆门市| 内乡县| 漾濞| 松阳县| 渭源县| 宜丰县| 庐江县| 高要市| 重庆市| 新河县| 遵义市| 嵩明县| 德格县| 贵阳市| 九台市| 阳城县| 岑巩县| 德保县| 三门县| 温泉县| 尤溪县| 景泰县| 乐至县| 福鼎市| 改则县| 辽源市| 万安县| 澄江县| 颍上县| 三原县| 辽宁省| 天门市| 新龙县| 喜德县| 安多县| 桑植县| 西林县|