USACO: Spinning Wheels

Spinning Wheels

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
分析:
这道题目的采用模拟即可,模拟360次(这之间一定可以回到初始状态)。每次利用times[ ]数组记录该度数拥有多少个缺口,而后通过每次旋转结束后统计times是否有等于5的,有则返回true,否则继续或无解。
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;

struct ss
{
       int s,t;
} a[6][1000];
int v[6];
int times[400];
int tot[6],ans;
bool can;

void check(int t)
{
     memset(times,0,sizeof(times));
     for (int i=1;i<=5;++i)
         for (int j=1;j<=tot[i];++j)
         {
             if (t) a[i][j].s=(a[i][j].s+v[i])%360;
             for (int k=0;k<=a[i][j].t;++k)
                 ++times[(a[i][j].s+k)%360];
         }
     for (int i=0;i<360;++i)
         if (times[i]>4)
         {
                       can=1;
                       ans=t;
                       return;
         }
}

int main()
{
    freopen("spin.in","r",stdin);
    freopen("spin.out","w",stdout);
    
    for (int i=1;i<=5;++i)
    {
        scanf("%d%d",&v[i],&tot[i]);
        for (int j=1;j<=tot[i];++j) scanf("%d%d",&a[i][j].s,&a[i][j].t);
    }
    
    for (int t=0;t<=360;++t)
        if (!can)
           check(t);
        
    if (can) printf("%d\n",ans);
    else printf("none\n");
    
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值