| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我是找不出错误数据了,看有哪位能钻研出一组错误的(1071 Illusive Chase)#include<iostream>
#include<vector>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int m,n;
cin>>m>>n;
//输入地图
int map[100][100]={0};
int K,L;
for(K=0;K<m;++K)
for(L=0;L<n;++L)
cin>>map[K][L];
//输入步数
int np=0;
int from,to;
char dir;
vector<int> f,t;
vector<char>d;
while(cin>>from>>to)
{
if(from==0 && to==0)break;
cin>>dir;
//cout<<from<<" "<<to<<" "<<dir<<endl;
f.push_back(from);
t.push_back(to);
d.push_back(dir);
++np;
}
int num=0;//可能开始点个数
for(K=0;K<m;++K)
{
for(L=0;L<n;++L)
{
if(map[K][L]==1)continue;
map[K][L]=2;//染色
int M=0;
int color=2;
//染色法(可能点路径置为n,n>=2)
while(M<np)
{
int ecolor=color;
int eK,eL;
++color;
//找寻染色点,然后对可能路径染色
for(eK=0;eK<m;++eK)
{
for(eL=0;eL<n;++eL)
{
//发现染色点
if(map[eK][eL]==ecolor)
{
//cout<<"color: "<<color<<endl;
map[eK][eL]=0;//该染色点还原
int e;
//向右的情况
if(d[M]=='R')
{
for(e=f[M];e<=t[M];++e)
{
//如果可能有路径,则染色
if( eL+e<n &&
map[eK][eL+e]!=1)map[eK][eL+e]=color;
//遇到阻隔则跳出循环,因为不能继续往前了
else break;
}
}
//向左的情况
if(d[M]=='L')
{
for(e=f[M];e<=t[M];++e)
{
//如果可能有路径,则染色
if(eL-e>=0 &&
map[eK][eL-e]!=1)map[eK][eL-e]=color;
//遇到阻隔则跳出循环,因为不能继续往前了
else break;
}
}
//向上的情况
if(d[M]=='U')
{
for(e=f[M];e<=t[M];++e)
{
//如果可能有路径,则染色
if(eK-e>=0 &&
map[eK-e][eL]!=1)map[eK-e][eL]=color;
//遇到阻隔则跳出循环,因为不能继续往前了
else break;
}
}
//向下的情况
if(d[M]=='D')
{
for(e=f[M];e<=t[M];++e)
{
//如果可能有路径,则染色
if(eK+e<m &&
map[eK+e][eL]!=1)map[eK+e][eL]=color;
//遇到阻隔则跳出循环,因为不能继续往前了
else break;
}
}
}//发现染色点处理结束
}
}//染色点处理结束
++M;
}//染色法结束
/*int i,j;
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
{
cout<<map[i][j]<<' ';
}
cout<<endl;
}
cout<<endl;*/
//看该点是否可行
int judge=0;
for(int eK=0;eK<m;++eK)
{
for(int eL=0;eL<n;++eL)
{
if(map[eK][eL]==color)
{
++num;
map[eK][eL]=0;
judge=1;
break;
}
}
if(judge==1)break;
}
}//L
}//K
cout<<num<<endl;
}//while(T--)
return 0;
}
/*
1 1 1 1
1 1 1 1
1 1 1 1
1 3 R
0 0
*/
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator