有五个不透明的圆盘,每个圆盘上有不超过五个扇形缺口,这五个圆盘重叠在一起,每个都有一个固定的速度旋转,问经过最短多久,光线可以穿过这些圆盘。
世道模拟题,但是一开始一直在纠结如何判断这个状态已经枚举过了,也就是判重的问题,后来才知道不用判重,当旋转次数超过360次,就会回到起始状态。
/*
ID: modengd1
PROG: spin
LANG: C++
*/
#include <iostream>
#include <stdio.h>
using namespace std;
struct wheel
{
int speed;
int hole;
int Sta[5],End[5];
};
wheel Wheel[5];
bool isPass()
{
int Passcounter;
for(int i=0;i<360;i++)
{
Passcounter=0;
for(int j=0;j<5;j++)
{
for(int k=0;k<Wheel[j].hole;k++)
{
if(i==270)
i=270;
if(Wheel[j].Sta[k]<=Wheel[j].End[k]&&i>=Wheel[j].Sta[k]&&Wheel[j].End[k]>=i)
{
Passcounter++;
break;
}
if(Wheel[j].Sta[k]>Wheel[j].End[k]&&(i>=Wheel[j].Sta[k]||Wheel[j].End[k]>=i))
{
Passcounter++;
break;
}
}
}
if(Passcounter==5)
return true;
}
return false;
}
int main()
{
freopen("spin.in","r",stdin);
freopen("spin.out","w",stdout);
//input
for(int i=0;i<5;i++)
{
scanf("%d%d",&Wheel[i].speed,&Wheel[i].hole);
for(int j=0;j<Wheel[i].hole;j++)
{
scanf("%d%d",&Wheel[i].Sta[j],&Wheel[i].End[j]);
Wheel[i].End[j]=(Wheel[i].End[j]+Wheel[i].Sta[j])%360;
}
}
//rotate
for(int i=0;i<360;i++)
{
if(isPass())
{
cout<<i<<endl;
return 0;
}
for(int j=0;j<5;j++)
{
for(int k=0;k<Wheel[j].hole;k++)
{
Wheel[j].Sta[k]=(Wheel[j].Sta[k]+Wheel[j].speed)%360;
Wheel[j].End[k]=(Wheel[j].End[k]+Wheel[j].speed)%360;
}
}
}
cout<<"none"<<endl;
return 0;
}
原文:http://www.cnblogs.com/modengdubai/p/4822565.html