USACO3.2.3--Spinning Wheels

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
题解:一个很水的模拟,我居然还撸了好久。。。把start angle and extent看成起始位置和终止位置了。。。entent的意思是长度或者范围的意思。。又一次没看清楚题。。。总想着找一下五个轮子的公共区间,如果有那么就是可以透光的。不过麻烦的问题是像150 90这种数据,和其他的求公共区间是很麻烦的,不过还是硬着头皮写下去,越陷越深,写了一百多行实在写不下去了。。回头看题才发现又一次被坑惨了!!!教训呀,以后一定要看清楚题,宁愿不要做那么快。其实往往看清楚题再来做会节省更多时间。如果没看清题就做,做完才发现没看清题的话,那就悲剧了。。特别是在比赛的时候。。。那就只能呵呵了。。。
View Code
 1 /*

 2 ID:spcjv51

 3 PROG:spin

 4 LANG:C

 5 */

 6 #include<stdio.h>

 7 #include<string.h>

 8 int speed[6],f[6][360],s[6][360];

 9 int main(void)

10 {

11     freopen("spin.in","r",stdin);

12     freopen("spin.out","w",stdout);

13     int i,j,k,time,ans,start,end;

14     memset(f,0,sizeof(f));

15     for(i=1; i<=5; i++)

16     {

17         scanf("%d%d",&speed[i],&ans);

18         for(j=1; j<=ans; j++)

19         {

20             scanf("%d%d",&start,&end);

21             for(k=start;k<=start+end;k++)

22             f[i][k%360]=1;

23         }

24     }

25     for(time=0;time<360;time++)

26     {

27         for(i=1;i<=5;i++)

28         for(j=0;j<360;j++)

29         s[i][(j+speed[i]*time)%360]=f[i][j];

30         for(j=0;j<360;j++)

31         if(s[1][j]&&s[2][j]&&s[3][j]&&s[4][j]&&s[5][j])

32         {

33             printf("%d\n",time);

34             return 0;

35         }

36     }

37     printf("none\n");             

38     return 0;

39 }

 



你可能感兴趣的:(USACO)