USACO 3.2 Spinning Wheels 单纯模逆

题目描述很复杂,但是数据很小,模逆轮子转动的过程就好啦

计算机真是强大

/*
ID: 15659801
LANG: C++
TASK: spin
*/
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;

struct wheel
{
    int speed;       //轮子速度
    int n;           //缺口个数
    int wedge_s[5];  //缺口起始位置
    int wedge_l[5];  //缺口长度
};
struct wheel w[5];


void scanff()
{
    for(int i=0; i<5; ++i)
    {
        cin >> w[i].speed >> w[i].n;
        for(int j=0; j<w[i].n; ++j)
        {
            cin >> w[i].wedge_s[j] >> w[i].wedge_l[j];
        }
    }
}
int through(void)  //检查光线是否能通过
{
    int flag[5][360]={0};
    for(int i=0; i<5; ++i)   //标记缺口位置
    {
        for(int j=0; j<w[i].n; ++j)
        {
            int k=0,start=w[i].wedge_s[j],len=w[i].wedge_l[j];
            while(k<=len)
            {
                flag[i][(start+k)%360]=1;
                ++k;
            }
        }
    }
    for(int t=0; t<360; ++t)  //检查光线是否能通过
    {
        int light=1;
        for(int i=0; i<5; ++i)
        {
            if(flag[i][t]==0)
            {
                light=0;
                break;
            }
        }
        if(light==1)
        {
            return 1;
            break;
        }
    }
    return 0;
}
int main ()
{
    freopen ("spin.in", "r",stdin);
    freopen ("spin.out", "w",stdout);
    scanff();
    int t=0;
    for(t=0; t<=360; ++t)
    {
        if(through())
        {
            printf("%d\n",t);
            fclose(stdin);
            fclose(stdout);
            exit(0);
        }
        for(int k1=0; k1<5; ++k1)   //模逆旋转过程
        {
            for(int k2=0; k2<w[k1].n; ++k2)
            {
                w[k1].wedge_s[k2]+=w[k1].speed;
                w[k1].wedge_s[k2] %= 360;
            }
        }
    }
    printf("none\n");
    fclose(stdin);
    fclose(stdout);
    exit (0);
}

猜你喜欢

转载自blog.csdn.net/daimaliang/article/details/82385290
3.2