• <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!
            題意:給你九個(gè)表的初始狀態(tài),每個(gè)表只可能是3,6,9,12,然后下面有9個(gè)操作,每個(gè)操作分把幾個(gè)表的指針順時(shí)針移動(dòng)90度
              要求給你一個(gè)初始狀態(tài),讓你給出一種方案(移動(dòng)操作的組合)使移動(dòng)后所有的表的指針都指向12
            提交了三次,第一次compile error 沒有包含string.h,下文用到了memset,低級(jí)錯(cuò)誤;
            第二次對(duì)于test無法通過。
            題解:用數(shù)組a[1……9 ]分別紀(jì)錄每個(gè)表移到12需要移動(dòng)的次數(shù),接受數(shù)據(jù)時(shí)a[i]=(12-a[i])/3;即可。
                         9重循環(huán)暴力所有情況,用cnt[1……9]記錄1……9個(gè)表的移動(dòng)次數(shù),如果可以使所有表都指向12的話就保存起來。
                       要注意的是:每個(gè)操作不超過四次,因?yàn)樗拇斡只氐匠跏嫉臓顟B(tài)沒有意義,表移動(dòng)的次數(shù)可以超過四次,比如test 3就讓A表移動(dòng)了6次,而a[1]==2,也就是第i個(gè)表 移動(dòng)的次數(shù)cnt[i]/4==a[i]才可,這也就是我test 3 錯(cuò)的原因。
                      最后如果有多個(gè)結(jié)果的話,是輸出使所有表移動(dòng)次數(shù)的和最小的那個(gè)

              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];        //需要移動(dòng)的次數(shù) 
             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 田兵 閱讀(1479) 評(píng)論(0)  編輯 收藏 引用 所屬分類: USACO

            <2010年6月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(2)

            隨筆分類(65)

            隨筆檔案(65)

            文章檔案(2)

            ACM

            搜索

            積分與排名

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            久久婷婷五月综合色奶水99啪| 精品少妇人妻av无码久久| 国产高潮国产高潮久久久| 7777精品伊人久久久大香线蕉| 成人午夜精品久久久久久久小说| 久久婷婷五月综合97色| 久久综合亚洲欧美成人| 77777亚洲午夜久久多人| 久久精品国产亚洲AV影院| 精品久久久久久久久免费影院| 亚洲精品乱码久久久久久不卡| 久久国产综合精品五月天| 久久人人超碰精品CAOPOREN| 久久国产成人精品国产成人亚洲| 国产精品免费久久久久影院| 国产日韩久久久精品影院首页| 99久久无码一区人妻| 久久婷婷五月综合色99啪ak| 青青久久精品国产免费看| 老男人久久青草av高清| 亚洲va国产va天堂va久久| 久久国产精品无码一区二区三区 | 久久久久亚洲精品男人的天堂| 大美女久久久久久j久久| 日本久久久久久久久久| 久久精品国产久精国产一老狼| 亚洲欧美伊人久久综合一区二区| 色88久久久久高潮综合影院 | 久久电影网2021| 国内精品伊人久久久久网站| 亚洲精品第一综合99久久| 久久精品国产2020| 国产欧美久久一区二区| 婷婷久久精品国产| 久久久久国产精品熟女影院 | 亚洲精品97久久中文字幕无码| 亚洲国产精品无码久久一线 | 久久e热在这里只有国产中文精品99 | 久久久婷婷五月亚洲97号色 | 一本一本久久A久久综合精品| 国产精品久久久久影院嫩草|