Usaco Spinning Wheels

Source: Internet
Author: User

Test instructions is to give you five wheels, each wheel has some openings, now each wheel from 0 position began to turn, ask the shortest time 5 wheel openings meet, just start to see this problem when there is no idea, like wait until the last in writing, and finally did not think of the solution, direct simulation on the line, the code is as follows: (attention to processing boundaries He is not a discrete 360 mouth, but an interval.

/*id:m1500293 lang:c++ Prog:spin*/#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;BOOLwhell[6][390];intw[5];intidx[5] = {0,0,0,0,0};intCheck () { for(intI=0; i< the; i++)    {        BOOLres =true;  for(intj=0; j<5; J + +) {res= res&whell[j][(idx[j]+i)% the]; }        if(RES)return true; }    return false;}intMain () {Freopen ("spin.in","R", stdin); Freopen ("Spin.out","W", stdout); memset (Whell,0,sizeof(Whell));  for(intI=0; i<5; i++) {scanf ("%d", &W[i]); intT; scanf ("%d", &t);  for(intj=0; j<t; J + +)        {            intSt, WI; scanf ("%d%d", &st, &WI);  for(intk=st; k<=st+wi; k++) Whell[i][k% the] =1; }    }     for(intI=0; i< the; i++)    {if(check ()) {printf ("%d\n", i); return 0; }         for(intj=0; j<5; J + +) {Idx[j]= ((Idx[j]-w[j])% the+ the)% the; Note that there may be a negative number, WA once}} printf ("none\n");}

Usaco Spinning Wheels

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.