# 模拟解Spinning Wheels

6 篇文章 0 订阅

## Spinning Wheels

1998 ACM NE Regionals

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

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

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

Wedges for each wheel are specified by an integer start angleand 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 wouldimagine.

At the start, which is time 0, all the wheels' alignment marksline up. Your program must determine the earliest time (integerseconds) at or after the start that some wedge on each wheel willalign with the wedges on the other wheel so that a light beam canpass through openings on all five wedges. The wedges can align atany part of the rotation.

### 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 nextW 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 thewedges align so a light beam can pass through them. Print none' (lowercase, no quotes) if the wedges will never align properly.

### SAMPLE OUTPUT (file spin.out)

9


### 部分借鉴blog

https://www.byvoid.com/blog/usaco-323-spinning-wheels/

### 通过代码

Executing...
Test 1: TEST OK [0.003 secs, 3500 KB]
Test 2: TEST OK [0.008 secs, 3500 KB]
Test 3: TEST OK [0.008 secs, 3500 KB]
Test 4: TEST OK [0.014 secs, 3500 KB]
Test 5: TEST OK [0.005 secs, 3500 KB]
Test 6: TEST OK [0.027 secs, 3500 KB]
Test 7: TEST OK [0.005 secs, 3500 KB]
Test 8: TEST OK [0.019 secs, 3500 KB]

/*
ID: c1033311
LANG: C++
*/
#include<stdio.h>

struct{
int s;
int len;
int e;
}wheel[5][5];

int speed[5],holeNum[5];

//枚举所有角度[0,359]，看光线是否能通过
int check(void){
int i,j,k;

for(i=0;i<360;++i) //角度
{
int sum=0;

for(j=0;j<5;++j)//轮子
{
for(k=0;k<holeNum[j];++k)
if((i>=wheel[j][k].s && i<=wheel[j][k].e)||(i<wheel[j][k].s && i+360<=wheel[j][k].e))
{
sum++;
break;
}
}
if(sum==5)
return 1;
}
return 0;
}

int main(){
FILE *fin=fopen("spin.in","r");
FILE *fout=fopen("spin.out","w");

int time;
int i,j;

//输入数据
for(i=0;i<5;++i){
fscanf(fin,"%d%d",&speed[i],&holeNum[i]);

for(j=0;j<holeNum[i];++j)
{
fscanf(fin,"%d%d",&wheel[i][j].s,&wheel[i][j].len);
wheel[i][j].s%=360;
wheel[i][j].e=wheel[i][j].s+wheel[i][j].len;
}
}

//求解
for(time=0;time<360;++time)
{
if(check()==1)
{
fprintf(fout,"%d\n",time);
break;
}
else //转动1s的距离
{
for(i=0;i<5;++i)
for(j=0;j<holeNum[i];++j)
{
wheel[i][j].s+=speed[i];
wheel[i][j].s%=360;
wheel[i][j].e=wheel[i][j].s+wheel[i][j].len;
}
}//end else
}

if(time==360)
fprintf(fout,"none\n");

return 0;
}`

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
10-21 501
02-27 1383
08-18 130
09-17 2485
03-27 824
09-07 789
04-14 4316
05-01 4826
07-02 5498
02-08 3803
02-20 2011

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。