USACO-Section 3.2-PROB 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

直接模拟旋转就好,每转一次把相应的缺口打标记


#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#define name "spin"
using namespace std;
bool qk[6][361];
int bj[6],t,flag;
struct spin
{
	int v,w;
	int ws[6],ww[6];
}sp[6];
int main()
{
	freopen(name ".in","r",stdin);
	freopen(name ".out","w",stdout);
	int i,j,k;
	for (i=1;i<=5;i++)
	  {
	  	bj[i]=0;
	  	cin>>sp[i].v>>sp[i].w;
	  	for (j=1;j<=sp[i].w;j++)
	  	{
	  	   cin>>sp[i].ws[j]>>sp[i].ww[j];
	  	   for (k=sp[i].ws[j];k<=sp[i].ws[j]+sp[i].ww[j];k++)
	  	     qk[i][k%360]=1;
	    }
	  }
	while (true)
	{
		for (i=0;i<=359;i++)
		if (qk[1][i]==1&&qk[2][i]==1&&qk[3][i]==1&&qk[4][i]==1&&qk[5][i]==1)
		  {cout<<t<<endl;flag=1;break;}
		if (flag==1) break;
		t++;
		if (t>360) {cout<<"none"<<endl;return 0;}
		memset(qk,false,sizeof(qk));
		for (i=1;i<=5;i++)
		{
			bj[i]+=sp[i].v;bj[i]%=360;
		    for (j=1;j<=sp[i].w;j++)
		    {
		       for (k=sp[i].ws[j];k<=sp[i].ws[j]+sp[i].ww[j];k++)
		         qk[i][(k+bj[i])%360]=1;
		    }
	    }
	}
	return 0;
}


发布了20 篇原创文章 · 获赞 0 · 访问量 5208

猜你喜欢

转载自blog.csdn.net/SoYouTry/article/details/50593920