• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            USACO chapter 1 section 1.4 clocks

            USER: tianbing tianbing [tbbd4261]
            TASK: clocks
            LANG: C++
            Compiling...
            Compile: OK
            Executing...
            Test 1: TEST OK [0.054 secs, 2932 KB]
            Test 2: TEST OK [0.043 secs, 2932 KB]
            Test 3: TEST OK [0.043 secs, 2932 KB]
            Test 4: TEST OK [0.054 secs, 2932 KB]
            Test 5: TEST OK [0.043 secs, 2932 KB]
            Test 6: TEST OK [0.043 secs, 2932 KB]
            Test 7: TEST OK [0.032 secs, 2932 KB]
            Test 8: TEST OK [0.032 secs, 2932 KB]
            Test 9: TEST OK [0.054 secs, 2932 KB]
            All tests OK.
            

            Your program ('clocks') produced all correct answers! This is your submission #3 for this problem. Congratulations!

            Here are the test data inputs:

            ------- test 1 -------
            9 9 12
            6 6 6
            6 3 6
            ------- test 2 -------
            12 9 12
            9 9 9
            12 9 12
            ------- test 3 -------
            6 9 3
            3 3 9
            12 12 12
            ------- test 4 -------
            9 3 9
            9 9 9
            9 9 9
            ------- test 5 -------
            6 12 12
            12 12 12
            12 12 12
            ------- test 6 -------
            3 12 9
            6 6 6
            12 12 12
            ------- test 7 -------
            12 3 3
            3 6 6
            12 3 6
            ------- test 8 -------
            12 3 9
            9 12 12
            3 6 9
            ------- test 9 -------
            9 12 9
            12 3 12
            9 12 9
            
            Keep up the good work!
            
            Thanks for your submission!
            題意:給你九個表的初始狀態,每個表只可能是3,6,9,12,然后下面有9個操作,每個操作分把幾個表的指針順時針移動90度
              要求給你一個初始狀態,讓你給出一種方案(移動操作的組合)使移動后所有的表的指針都指向12
            提交了三次,第一次compile error 沒有包含string.h,下文用到了memset,低級錯誤;
            第二次對于test無法通過。
            題解:用數組a[1……9 ]分別紀錄每個表移到12需要移動的次數,接受數據時a[i]=(12-a[i])/3;即可。
                         9重循環暴力所有情況,用cnt[1……9]記錄1……9個表的移動次數,如果可以使所有表都指向12的話就保存起來。
                       要注意的是:每個操作不超過四次,因為四次又回到初始的狀態沒有意義,表移動的次數可以超過四次,比如test 3就讓A表移動了6次,而a[1]==2,也就是第i個表 移動的次數cnt[i]/4==a[i]才可,這也就是我test 3 錯的原因。
                      最后如果有多個結果的話,是輸出使所有表移動次數的和最小的那個

              1 /*
              2 ID:tbbd4261
              3 PROG:clocks
              4 LANG:C++
              5 */
              6 
              7 #include<iostream>
              8 #include<fstream>
              9 #include<cstring>
             10 #include<vector>
             11 using namespace std;
             12 int a[10];        //需要移動的次數 
             13 int cnt[10]={0};
             14 void f1(int i)
             15 {
             16 cnt[1]+=i; cnt[2]+=i; cnt[4]+=i; cnt[5]+=i;
             17 }
             18 
             19 void f2(int i)
             20 {
             21 cnt[1]+=i; cnt[2]+=i; cnt[3]+=i; 
             22 }
             23 
             24 void f3(int i)
             25 {
             26 cnt[2]+=i; cnt[3]+=i; cnt[5]+=i; cnt[6]+=i;
             27 }
             28 
             29 void f4(int i)
             30 {
             31 cnt[1]+=i; cnt[4]+=i; cnt[7]+=i;
             32 }
             33 
             34 void f5(int i)
             35 {
             36 cnt[2]+=i; cnt[4]+=i; cnt[5]+=i; cnt[6]+=i;cnt[8]+=i;
             37 }
             38 
             39 void f6(int i)
             40 {
             41 cnt[3]+=i; cnt[6]+=i; cnt[9]+=i;
             42 }
             43 
             44 void f7(int i)
             45 {
             46 cnt[4]+=i; cnt[5]+=i; cnt[7]+=i; cnt[8]+=i;
             47 }
             48 
             49 void f8(int i)
             50 {
             51      cnt[7]+=i; cnt[8]+=i; cnt[9]+=i;
             52 }
             53 
             54 void f9(int i)
             55 {
             56 cnt[5]+=i; cnt[6]+=i; cnt[8]+=i; cnt[9]+=i;
             57 }
             58 
             59 int check()
             60 {
             61 bool is_ans=1
             62  for(int i=1; i<=9; i++)
             63  {
             64    if(cnt[i]%4!=a[i])is_ans=0;//原寫成cnt[i]!=a[i],這樣就沒有操作的組合符合條件
             65  }    
             66  if(is_ans)return 1;
             67  else return 0;
             68 }
             69 vector<vector< int > >vec; 
             70  
             71 void push(int i1,int i2,int i3,int i4,int i5,int i6,int i7,int i8,int i9,int &min)
             72 {
             73      vector<int>tem;
             74      for(int i=1;i<=i1&&i1!=0;i++)tem.push_back(1);
             75      for(int i=1;i<=i2&&i2!=0;i++)tem.push_back(2);
             76      for(int i=1;i<=i3&&i3!=0;i++)tem.push_back(3);
             77      for(int i=1;i<=i4&&i4!=0;i++)tem.push_back(4);
             78      for(int i=1;i<=i5&&i5!=0;i++)tem.push_back(5);
             79      for(int i=1;i<=i6&&i6!=0;i++)tem.push_back(6);
             80      for(int i=1;i<=i7&&i7!=0;i++)tem.push_back(7);
             81      for(int i=1;i<=i8&&i8!=0;i++)tem.push_back(8);
             82      for(int i=1;i<=i9&&i9!=0;i++)tem.push_back(9);
             83      vec.push_back(tem);
             84      //int sum=tem.size();
             85      //if(sum<min){ min=sum; vec.clear(); vec.push_back(tem); }
             86      //else if(sum==min)vec.push_back(tem);
             87 }
             88 
             89 int main()
             90 {
             91     ifstream cin("clocks.in");
             92     ofstream cout("clocks.out");  
             93     int min=10000
             94     for(int i=1; i<=9; i++)
             95       { cin>>a[i]; a[i]=(12-a[i])/3; }
             96     for(int i1=0; i1<4; i1++)
             97     for(int i2=0; i2<4; i2++)
             98     for(int i3=0; i3<4; i3++)
             99     for(int i4=0; i4<4; i4++)
            100     for(int i5=0; i5<4; i5++)
            101     for(int i6=0; i6<4; i6++)
            102     for(int i7=0; i7<4; i7++)
            103     for(int i8=0; i8<4; i8++)
            104     for(int i9=0; i9<4; i9++)
            105     {
            106      f1(i1); f2(i2); f3(i3); f4(i4); f5(i5); f6(i6); f7(i7);  f8(i8); f9(i9);
            107      int v=check();
            108      if(v==1)
            109        push(i1,i2,i3,i4,i5,i6,i7,i8,i9,min);
            110      memset(cnt,0,sizeof cnt);
            111     }
            112     
            113     int mov[10]={0,4,3,4,3,5,3,4,3,4};
            114     vector<int> temp; int m=10000;
            115       
            116      for(int i=0; i<vec.size(); i++)
            117       {
            118         int sum=0;   
            119         for(int j=0; j<vec[i].size();j++)
            120           sum+=mov[vec[i][j]];
            121         if(sum<m)
            122         { m=sum; temp=vec[i]; }
            123       }
            124       cout<<temp[0];
            125       for(int i=1; i<temp.size(); i++)
            126       cout<<' '<<temp[i];
            127       cout<<endl;
            128   
            129    //system("pause");
            130     return 0;
            131 }
            132 

            posted on 2010-06-03 10:09 田兵 閱讀(1478) 評論(0)  編輯 收藏 引用 所屬分類: USACO

            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            導航

            統計

            常用鏈接

            留言簿(2)

            隨筆分類(65)

            隨筆檔案(65)

            文章檔案(2)

            ACM

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            精品熟女少妇aⅴ免费久久| 亚洲国产成人久久精品动漫| 亚洲国产成人精品女人久久久 | 久久久久亚洲AV无码观看| 午夜精品久久久久9999高清| 色综合久久中文字幕无码| 久久免费高清视频| 一本色道久久综合狠狠躁篇 | 嫩草影院久久99| 人妻中文久久久久| 97久久天天综合色天天综合色hd| 久久91精品综合国产首页| 久久综合88熟人妻| 久久中文字幕无码专区| 久久精品国产亚洲AV高清热| 久久夜色撩人精品国产| 99久久久国产精品免费无卡顿| 伊人 久久 精品| 久久99精品久久久久久噜噜| 99久久99久久精品免费看蜜桃| 亚洲欧美国产日韩综合久久| 国产精品激情综合久久| 91精品国产综合久久婷婷| 久久久久亚洲AV成人网人人网站| 久久久久久国产精品免费免费| 国产V亚洲V天堂无码久久久| 中文字幕久久久久人妻| 伊人久久一区二区三区无码| 精品久久久久久99人妻| 国产一区二区三区久久| 国内精品久久久久久久97牛牛 | 国产成人精品久久亚洲高清不卡| 亚洲精品国产美女久久久| 久久无码中文字幕东京热| 成人精品一区二区久久久| 久久99久久99小草精品免视看| 久久亚洲私人国产精品vA| 色88久久久久高潮综合影院| 久久99国产精品尤物| 国产午夜免费高清久久影院| 97久久久精品综合88久久|