隨筆-28  評(píng)論-51  文章-10  trackbacks-0
          //pku1006 源代碼分析
          //注釋掉的是第一次寫的,用的是窮舉的方法,輸出結(jié)//果都正確,但是time limited,想想也是哦,這么
          //做,三次循環(huán),不超時(shí)才怪啊,
          //現(xiàn)在的代碼采用逆推方法,一個(gè)循環(huán),快多了:)
          //總結(jié):寫代碼,首要的是解題思路要對(duì)頭,要高效,//然后有可能才考慮代碼優(yōu)化,性能提高的問題!!!//切記!!
          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
          ++;
                  }
              }
          }

          //有的時(shí)候是思想方法不多,才使程序通不過,只有思想方法,解題方法正確以后,才考慮程序的優(yōu)化問題,才有意義!
          //    自已編寫的可以得出正確結(jié)果,但是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) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 无锡市| 宜州市| 三江| 稷山县| 察隅县| 师宗县| 金阳县| 娱乐| 金门县| 海兴县| 榆林市| 临武县| 含山县| 乌什县| 乌苏市| 嵊泗县| 旅游| 伊川县| 湟中县| 邵武市| 津市市| 平乡县| 三门峡市| 马公市| 仙居县| 唐河县| 雅江县| 普定县| 正宁县| 藁城市| 黑山县| 昆山市| 慈溪市| 滁州市| 本溪市| 科技| 谢通门县| 重庆市| 株洲市| 邹城市| 临漳县|