# USACO Section 3.2 PROB Spinning Wheels

3 篇文章 0 订阅

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
`

1. 如何判断是否能有光线穿过；2. 什么时候应该终止，即永远都不能有光线穿过。

1. 判断光线穿过：

2. 何时终止：

/*
ID: randyji1
PROG: spin
LANG: C++
*/

#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cassert>
#include <cstring>
using namespace std;

ifstream fin("spin.in");
ofstream fout("spin.out");

const int NUM = 5;

struct Wheel {
int speed;
int n;
int start[NUM];
int extent[NUM];
int position;
};

Wheel wheels[NUM];

void getInput() {
for(int i = 0; i < NUM; i++) {
fin >> wheels[i].speed >> wheels[i].n;
for(int j = 0; j < wheels[i].n; j++) {
fin >> wheels[i].start[j] >> wheels[i].extent[j];
}
wheels[i].position = 0;
}
}

bool isQualifiedState() {
unsigned int mark[360];
memset(mark, 0, sizeof(unsigned int) * 360);

for(int w = 0; w < NUM; w++) {
unsigned int sign = (0x1 << w);
for(int hole = 0; hole < wheels[w].n; hole++) {
int begPosition = wheels[w].position + wheels[w].start[hole];
for(int i = 0; i <= wheels[w].extent[hole]; i++) {
int degree = (begPosition + i) % 360;
mark[degree] |= sign;
}
}
}

for(int i = 0; i < 360; i++)
if(mark[i] == ((0x1 << NUM) - 1)) return true;
return false;
}

void rotate() {
for(int i = 0; i < NUM; i++)
wheels[i].position = (wheels[i].position + wheels[i].speed) % 360;
}

void printMinTime() {
for(int i = 0; i < 360; i++) {
if(isQualifiedState()) {
fout << i << endl;
return;
}
rotate();
}
fout << "none" << endl;
}

int main() {
assert(fin && fout);
getInput();
printMinTime();

return 0;
}

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
08-17 335
08-25 431
05-18 766

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