procedure2012
It's not worth it to know you're not worth it!

[关键字]:模拟 枚举

[题目大意]:有5个轮子,每个轮子优r个缺口并且会按一定速度不停转动,问什么时候可以使一条光线射过所有轮子。

//======================================================================================================================================

[分析]:从0到1000(或其他的)枚举分钟然后判断,当前分钟是否有解。如果有解就输出并结束否则继续直到枚举完所有分钟还没找到解就是无解的情况。usaco第3章还有这么水的题……

[代码]:

View Code
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

int v[6],l,s,w,ans;
int e[360];
bool b[6][360];

bool Cleck(int h)
{
memset(e,0,sizeof(e));
for (int i=1;i<=5;i++)
for (int j=0;j<360;j++)
if (b[i][j]) e[(j+v[i]*h)%360]++;
for (int i=0;i<360;i++)
if (e[i]==5) return 1;
return 0;
}

int main()
{
freopen("input4.txt","r",stdin);
freopen("out.txt","w",stdout);
memset(b,0,sizeof(b));
for (int i=1;i<=5;i++)
{
scanf("%d%d",&v[i],&w);
for (int j=1;j<=w;j++)
{
scanf("%d%d",&s,&l);
for (int k=s;k<=s+l;k++) b[i][k%360]=1;
}
}
ans=-1;
for (int i=0;i<=10000;i++)
if (Cleck(i)) {ans=i;break;}
if (ans==-1) printf("none\n"); else printf("%d\n",ans);
return 0;
}



posted on 2012-02-25 18:18  procedure2012  阅读(311)  评论(0编辑  收藏  举报