[Usaco 3.2.3] Spinning Wheel

Source: Internet
Author: User
[Description]

A textile car has five spinning wheels, and these five non-transparent wheels have some gaps on the edges. These gaps must be quickly and accurately arranged. Each wheel has a starting mark (at 0 degrees) so that all wheels can start to rotate at a unified known position. The wheels rotate in the direction where the angle is larger (that is, 0 goes through the rotation to reach the position of 1), so from the starting position, they turn 1 degree in sequence within a certain period of time, 2 degrees and so on (although these wheels may not turn these angles at the same time ).

This is an integer problem. The wheel does not turn an angle of 1.5 degrees or 23.51234123 degrees. For example, the wheel may turn 20 to 25 degrees or even 30 to 40 degrees in one second (if it turns fast ).

All angles in this problem are limited to 0 <= angle <= 359. After the wheel turns 359 degrees, the next step is 0 degrees. Each wheel has a fixed rotation speed, in the unit of angle/second. 1 <= speed <= 180.

The start angle and length of the gap on the wheel are represented by an integer in units of degree. There is at least one interval between two gaps on one wheel.

At the starting position, set the time to 0. Start marks of all wheels are arranged in a straight line. Your program must calculate that the gap on each wheel is first aligned with the gap on other wheels (that is, a ray of light can pass through five gaps on five wheels) time of the condition. These gaps are aligned at any angle.

[Format] program name: spininput format :( file spin. In)

The five elements in the input correspond to five wheels.

The first digit indicates the rotation speed of the wheel. The next number is the number of gaps W. 1 <= W <= 5. The following W pairs represent the start angle and length of each gap.

Output Format :( file spin. out)

Only one row, including an integer, indicates the earliest time when light can pass through these five wheels. If there is no solution, output 'none' (lower case, without quotation marks ).

[Analysis]

Enumeration directly ......

1 # include <cstdlib> 2 # include <iostream> 3 # include <cstdio> 4 # include <cstring> 5 # include <cmath> 6 # include <iostream> 7 # include <fstream> 8 using namespace STD; 9 struct wheel {int SPD, start [6], Len [6], size;} W [5]; 10 int main () 11 {12 short SP [361]; 13 // file operation 14 freopen ("spin. in "," r ", stdin); 15 freopen (" spin. out "," W ", stdout); 16 int time, I, J, K; 17 for (I = 0; I <5; I ++) 18 {19 scanf ("% d", & W [I]. SPD, & J); 20 W [I]. size = J; 21 While (-- j> = 0) scanf ("% d", & W [I]. start [J], & W [I]. len [J]); 22} 23 24 for (time = 0; time <360; time ++) 25 {26 for (I = 0; I <360; I ++) SP [I] =-1; 27 for (I = 0; I <5; I ++) 28 {29 for (j = 0; j <W [I]. size; j ++) 30 {31 for (k = W [I]. start [J]; k <= W [I]. start [J] + W [I]. len [J]; k ++) 32 If (SP [K % 360] = i-1) SP [K % 360] = I; 33 W [I]. start [J] = (W [I]. start [J] + W [I]. SPD) % 360; 34} 35} 36 for (I = 0; I <360; I ++) 37 If (SP [I] = 4) 38 {39 printf ("% d", time); 40 return 0; 41} 42} 43 printf ("NONE"); 44 return 0; 45}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.