我的USACO第50题,一个98年ACM区域赛的题,谈不上什么算法,模拟求解。s[i][j][0]表示第i个轮子上第j个缺口的起始角度,s[i][j][1]表示第i个轮子上第j个缺口的长度。时间每增加1s,检测光线是否可以穿过所有的轮子,如果是则输出结果结束;如果否,检测将本次每个轮子的第一个缺口的起始角度是否以前曾出现过,如果是,则问题进入死循环,不可能有光线穿过五个轮子,输出"none"结束;如果否,则将本次每个轮子的第一个缺口的起始角度存进vec,ans++,继续循环。这里题目中说0~180的长度是181,但是编程中如果这样处理则会错误,例如题目中给出的测试例结果为9,此时第三个轮子的缺口起始角度为90,长度为180,按题中的意思,最多能达到的角度为90+180-1=269,但是答案光线却是270度,依此,在编程中做出了适当修改。
修改了题意,抱着试试的态度提交,竟然一次通过,而且用时还可以,激动啊激动,好久没WORKED FIRST TIME了,难道是为了纪念我的USACO50题?留下截图,以作纪念。
USER: jinzhou lee [jzzlee1]
TASK: spin
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.000 secs, 3340 KB]
Test 2: TEST OK [0.000 secs, 3340 KB]
Test 3: TEST OK [0.000 secs, 3340 KB]
Test 4: TEST OK [0.000 secs, 3340 KB]
Test 5: TEST OK [0.000 secs, 3340 KB]
Test 6: TEST OK [0.011 secs, 3340 KB]
Test 7: TEST OK [0.011 secs, 3340 KB]
Test 8: TEST OK [0.032 secs, 3340 KB]
All tests OK.
YOUR PROGRAM ('spin') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.
/*
ID:jzzlee1
PROB:spin
LANG:C++
*/
//#include<iostream>
#include<fstream>
#include<cmath>
#include<vector>
using namespace std;
ifstream cin("spin.in");
ofstream cout("spin.out");
int ans,v[5],w[5],s[5][5][2];
struct node
{
short a;
short b;
short c;
short d;
short e;
};
vector<node> vec;
bool checkok()
{
bool flag,sign;
for(int k=0;k!=360;k++)
{
sign=1;
for(int i=0;i!=5;i++)
{
flag=0;
for(int j=0;j!=w[i];j++)
{
if(s[i][j][0]+s[i][j][1]-1<360)
{
if(k>=s[i][j][0]&&k-s[i][j][0]<=s[i][j][1])
{
flag=1;
break;
}
}
else
{
if(k<s[i][j][0])
{
if(k+360-s[i][j][0]<s[i][j][1])
{
flag=1;
break;
}
}
else
{
if(k-s[i][j][0]<s[i][j][1])
{
flag=1;
break;
}
}
}
}
if(!flag)
sign=0;
}
if(sign)
return 1;
}
return 0;
}
bool checkfail()
{
vector<node>::iterator iter;
for(iter=vec.begin();iter!=vec.end();iter++)
{
if(iter->a!=s[0][0][0])
continue;
if(iter->b!=s[1][0][0])
continue;
if(iter->c!=s[2][0][0])
continue;
if(iter->d!=s[3][0][0])
continue;
if(iter->e!=s[4][0][0])
continue;
return 1;
}
return 0;
}
int main()
{
int i,j;
for(i=0;i!=5;i++)
{
cin>>v[i]>>w[i];
for(j=0;j!=w[i];j++)
{
cin>>s[i][j][0]>>s[i][j][1];
}
}
while(1)
{
if(checkok())
{
cout<<ans<<endl;
break;
}
for(i=0;i!=5;i++)
for(j=0;j!=w[i];j++)
s[i][j][0]=(s[i][j][0]+v[i])%360;
node dd;
dd.a=s[0][0][0];
dd.b=s[1][0][0];
dd.c=s[2][0][0];
dd.d=s[3][0][0];
dd.e=s[4][0][0];
if(checkfail())
{
cout<<"none"<<endl;
break;
}
vec.push_back(dd);
ans++;
}
return 0;
}

所有评论(0)