USACOSpinning Wheels

来源:http://ace.delos.com/usacoprob2?a=ahwL0nwmf1s&S=spin

暴力,水水的过了。

耗时估计是:360*360*n,n为总的缺口数。

由于n越大,缺口数越多,通光的几率越大,故根本不必在意时间的消耗。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

struct data
{
    int v;
    int n;
    int a[100],b[100];
    void add()
    {
        for (int i=0; i<n; i++)
            a[i] = (a[i]+v) % 360;
    }
}f[5];

int d[365];

bool check()
{
    memset(d,0,sizeof(d));
    for (int i=0; i<5; i++)
    {
        for (int j=0; j<f[i].n; j++)
            for (int x=f[i].a[j],k=0; k<=f[i].b[j]; k++,x++)
            {
                if (x==360) x=0;
                d[x]++;
            }
    }
    for (int i=0; i<360; i++)
        if (d[i]>=5) return true;
    return false;
}

int main()
{
    freopen("spin.in","r",stdin);
    freopen("spin.out","w",stdout);

    memset(f,0,sizeof(f));
    for (int i=0; i<5; i++)
    {
        cin>>f[i].v>>f[i].n;
        for (int j=0; j<f[i].n; j++)
            cin>>f[i].a[j]>>f[i].b[j];
    }

    int time=0;
    while (!check() && time<360)
    {
        time++;
        for (int i=0; i<5; i++)
            f[i].add();
    }
    if (time>=360) cout<<"none"<<endl;
    else cout<<time<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/ay27/p/2938952.html