usaco-3.2-spin-pass

來源:互聯網
上載者:User

標籤:style   blog   color   io   os   ar   for   art   div   

    類比題,量不大。

    轉動360秒以後,所有輪子回到起始角度。因此如果360秒以後還沒有出現重合情況的話,就可以退出迴圈了。

    如何判斷五個輪子重合呢?起初我也沒有很好的方法,一個個去判斷重合地區實在是太麻煩了。後來想到一個好方法。把 360度的輪子分成360個地區,用整形數組表示,如果一個輪子的缺口在這個地區內,則這個小地區加1,計算5個輪子的所有缺口。然後遍曆這個數組,如果 有個地區的值>=5,表明這個地區上面至少有5個缺口,則5個缺口重合,退出迴圈。

/*ID: qq104801LANG: C++TASK: spin*/#include <iostream>#include <fstream>#include <bitset>#include <cstdio>#include <algorithm>using namespace std;#define PI 360int speed[6];bitset<PI> curr[6],next[6];void test(){        freopen("spin.in","r",stdin);    freopen("spin.out","w",stdout);    int num,start,end;    for(int i=1;i<=5;i++)    {        cin>>speed[i]>>num;        for(int j=1;j<=num;j++)        {            cin>>start>>end;            end+=start;            for(int k=start;k<=end;k++)                curr[i].set(k%PI);        }    }    int angle=0;    bool flag;    while(angle<PI)    {        for(int i=0;i<PI;++i)        {            flag=false;            for(int j=1;j<=5;j++)                if(!curr[j].test(i))                {                    flag=true;                    break;                }            if(!flag)            {                cout<<angle<<endl;                return;            }            }                    for(int i=1;i<=5;i++)        {            for(int j=0;j<PI;j++)                next[i][j]=curr[i][(j+PI-speed[i])%PI];            curr[i]=next[i];        }        ++angle;    }    cout<<"none"<<endl; }int main () {            test();            return 0;}

test data:

USACO TrainingGrader Results     9 users onlineCHN/3 IND/1 IRN/1 KGZ/1 ROM/1 USA/1 VNM/1USER: cn tom [qq104801]TASK: spinLANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.005 secs, 3376 KB]   Test 2: TEST OK [0.019 secs, 3376 KB]   Test 3: TEST OK [0.032 secs, 3376 KB]   Test 4: TEST OK [0.019 secs, 3376 KB]   Test 5: TEST OK [0.003 secs, 3376 KB]   Test 6: TEST OK [0.016 secs, 3376 KB]   Test 7: TEST OK [0.008 secs, 3376 KB]   Test 8: TEST OK [0.030 secs, 3376 KB]All tests OK.YOUR PROGRAM (‘spin‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations.Here are the test data inputs:------- test 1 ----30 1 0 120180 1 10 10035 1 20 9031 1 30 8032 1 50 60------- test 2 ----30 1 350 350180 1 10 10035 1 67 2331 1 30 432 1 50 7------- test 3 ----180 1 0 120180 1 120 120180 1 240 12031 1 30 432 1 50 7------- test 4 ----1 1 140 3591 1 200 3591 1 4 12 1 6 11 1 300 300------- test 5 ----45 5 140 13 300 17 0 15 20 3 40 173 1 200 359105 2 4 1 50 50179 3 6 1 8 1 359 33 1 300 300------- test 6 ----45 5 120 13 200 17 0 15 20 3 32 173 5 200 100 1 30 50 10 70 2 75 1105 2 100 1 50 20179 3 6 1 8 1 359 33 1 300 359------- test 7 ----73 5 207 101 1 35 57 11 71 2 75 145 5 125 13 200 17 0 15 20 3 32 196 5 100 12 50 13 0 2 300 39 250 1119 5 6 1 8 1 359 1 245 1 123 115 5 300 1 231 1 185 1 179 2 0 18------- test 8 ----73 5 207 11 1 35 57 11 71 2 75 145 5 125 3 200 17 0 15 20 3 32 196 5 100 1 50 1 0 2 300 39 250 1119 5 6 1 8 1 359 1 245 1 123 115 5 300 1 231 1 185 1 179 2 0 1Keep up the good work!Thanks for your submission!

 

usaco-3.2-spin-pass

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.