zoukankan      html  css  js  c++  java
  • USACO Section 3.2 Spinning Wheels (spin)

    Spinning Wheels
    1998 ACM NE Regionals

    Each of five opaque spinning wheels has one or more wedges cut out of its edges. These wedges must be aligned quickly and correctly. Each wheel also has an alignment mark (at 0 degrees) so that the wheels can all be started in a known position. Wheels rotate in the `plus degrees' direction, so that shortly after they start, they pass through 1 degree, 2 degrees, etc. (though probably not at the same time).

    This is an integer problem. Wheels are never actually at 1.5 degrees or 23.51234123 degrees. For example, the wheels are considered to move instantaneously from 20 to 25 degrees during a single second or even from 30 to 40 degrees if the wheel is spinning quickly.

    All angles in this problem are presumed to be integers in the range 0 <= angle <= 359. The angle of 0 degrees follows the angle of 359 degrees. Each wheel rotates at a certain integer number of degrees per second, 1 <= speed <= 180.

    Wedges for each wheel are specified by an integer start angle and integer angle size (or `extent'), both specified in degrees. Wedges in the test data will be separated by at least one degree. The 'extent' also includes the original "degree" of the wedge, so '0 180' means degrees 0..180 inclusive -- one more than most would imagine.

    At the start, which is time 0, all the wheels' alignment marks line up. Your program must determine the earliest time (integer seconds) at or after the start that some wedge on each wheel will align with the wedges on the other wheel so that a light beam can pass through openings on all five wedges. The wedges can align at any part of the rotation.

    PROGRAM NAME: spin

    INPUT FORMAT

    Each of five input lines describes a wheel.

    The first integer on an input line is the wheel's rotation speed. The next integer is the number of wedges, 1 <= W <= 5. The next W pairs of integers tell each wedge's start angle and extent.

    SAMPLE INPUT (file spin.in)

    30 1 0 120
    50 1 150 90
    60 1 60 90
    70 1 180 180
    90 1 180 60
    

    OUTPUT FORMAT

    A single line with a single integer that is the first time the wedges align so a light beam can pass through them. Print `none' (lower case, no quotes) if the wedges will never align properly.

    SAMPLE OUTPUT (file spin.out)

    9
    思路:我是暴力的,但是判断是否合法绞尽了我的脑汁,最后还是A了,细节问题啊!!!
    Executing...
       Test 1: TEST OK [0.000 secs, 3228 KB]
       Test 2: TEST OK [0.000 secs, 3228 KB]
       Test 3: TEST OK [0.000 secs, 3228 KB]
       Test 4: TEST OK [0.000 secs, 3228 KB]
       Test 5: TEST OK [0.000 secs, 3228 KB]
       Test 6: TEST OK [0.000 secs, 3228 KB]
       Test 7: TEST OK [0.000 secs, 3228 KB]
       Test 8: TEST OK [0.022 secs, 3228 KB]
    
    All tests OK.
      1 /*
      2 ID:wuhuaju2
      3 PROG:spin
      4 LANG:C++
      5 */
      6 #include <cstdio>
      7 #include <iostream>
      8 #include <cstdlib>
      9 #include <algorithm>
     10 #include <cstring>
     11 #include <string>
     12 using namespace std;
     13 
     14 bool f[370];
     15 int a[10][10],st[10][10],en[10][10],zh[10],tot[10];
     16 int x,y,ans,n,x1,x2,y1,y2;
     17 bool flag;
     18 
     19 void close()
     20 {
     21     fclose(stdin);
     22     fclose(stdout);
     23     exit(0);
     24 }
     25 
     26 bool chuli(int x1,int y1,int x2,int y2)
     27 {
     28     if (x1>=x2 && x1<=y2) return true;
     29     if (y1<=y2 && y1>=x2) return true;
     30     if (x1<=x2 && y1>=y2) return true;
     31     if (x1>=x2 && y2>=y1) return true;
     32     return false;
     33 }
     34 
     35 bool ju()
     36 {
     37     for (int i=1;i<=5;i++)
     38     {
     39         for (int j=i+1;j<=5;j++)
     40         {
     41             x1=a[i][1];y1=a[i][2];
     42             x2=a[j][1];y2=a[j][2];
     43             if (x1>y1)
     44             {
     45                 if (x2>y2)
     46                 {
     47                     if (chuli(x1,359,x2,359))
     48                         continue;
     49                     if (chuli(0,y1,0,y2))
     50                         continue;
     51                     return false;
     52                 }
     53                 if (chuli(x1,359,x2,y2))
     54                     continue;
     55                 if (chuli(0,y1,x2,y2))
     56                     continue;
     57             }
     58             else
     59             {
     60                 if (x2>y2)
     61                 {
     62                     if (chuli(x1,y1,x2,359))
     63                         continue;
     64                     if (chuli(x1,y1,0,y2))
     65                         continue;
     66                     return false;
     67                 }
     68                 if (chuli(x1,y1,x2,y2))
     69                     continue;
     70             }
     71             return false;
     72         }
     73     }
     74     /*
     75     for (int i=1;i<=5;i++)
     76         cout<<a[i][1]<<" "<<a[i][2]<<" ";
     77     cout<<endl;
     78     */
     79     return true;
     80 }
     81 
     82 bool judge()
     83 {
     84     for (int q=1;q<=tot[1];q++)
     85     {
     86         for (int w=1;w<=tot[2];w++)
     87         {
     88             for (int e=1;e<=tot[3];e++)
     89             {
     90                 for (int r=1;r<=tot[4];r++)
     91                 {
     92                     for (int t=1;t<=tot[5];t++)
     93                     {
     94                         a[1][1]=st[1][q];a[1][2]=en[1][q];
     95                         a[2][1]=st[2][w];a[2][2]=en[2][w];
     96                         a[3][1]=st[3][e];a[3][2]=en[3][e];
     97                         a[4][1]=st[4][r];a[4][2]=en[4][r];
     98                         a[5][1]=st[5][t];a[5][2]=en[5][t];
     99                         /*
    100                         for (int i=1;i<=5;i++)
    101                         {
    102                             for (int j=i+1;j<=5;j++)
    103                             {
    104                                 if (a[i][2]<a[i][1]) // 240 30
    105                                 {
    106                                     if (min(a[j][1],a[j][2])<=a[i][1])
    107                                         continue;
    108                                     if (a[j][1])
    109                                 }
    110                                 */
    111                         if (ju())
    112                             return true;
    113                     }
    114                 }
    115             }
    116         }
    117     }
    118             return false;
    119 }
    120 
    121 
    122 void work()
    123 {
    124     ans=0;
    125     while (ans<=360)  //change!!
    126     {
    127         if (judge())
    128         {
    129             printf("%d\n",ans);
    130             close();
    131         }
    132         for (int i=1;i<=5;i++)
    133         {
    134             for (int j=1;j<=tot[i];j++)
    135             {
    136                 st[i][j]=(st[i][j]+zh[i]) % 360;
    137                 en[i][j]=(en[i][j]+zh[i]) % 360;
    138             }
    139         }
    140         ans++;
    141     }
    142     cout<<"none"<<endl;
    143 }
    144 
    145 void init ()
    146 {
    147 freopen("spin.in","r",stdin);
    148 freopen("spin.out","w",stdout);
    149    for (int i=1;i<=5;i++)
    150     {
    151         scanf("%d %d",&zh[i],&tot[i]);
    152         for (int j=1;j<=tot[i];j++)
    153         {
    154             scanf("%d %d",&st[i][j],&en[i][j]);
    155             en[i][j]=(en[i][j]+st[i][j]) % 360;
    156         }
    157     }
    158         
    159 }
    160 
    161 int main ()
    162 {
    163     init();
    164     work();
    165     close();
    166     return 0;
    167 }
    
    
    
     
  • 相关阅读:
    在进行页面的DIV CSS排版时,遇到IE6(当然有时Firefox下也会偶遇)浏览器中的图片元素img下出现多余空白的问题绝对是常见的对于该问题的解决方法也是“见机行事”。
    关于图片加载问题
    隐藏iframe边框
    设计模式-状态模式(State)
    软件设计原则
    设计模式-原型模式(Prototype)【重点:浅复制与深复制】
    设计模式-观察者模式(Observer)
    【Parallel】.Net 并行执行程序的使用心得
    个人对【依赖倒置(DIP)】、【控制反转(IOC)】、【依赖注入(DI)】浅显理解
    设计模式-建造者模式(Builder)
  • 原文地址:https://www.cnblogs.com/cssystem/p/2910658.html
Copyright © 2011-2022 走看看