POJ2632
来源:互联网 发布:晾霸 好太太 知乎 编辑:程序博客网 时间:2024/05/21 17:12
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int gra[105][105];
struct node
{
int xx,yy,sta;
}ro[105];
int k,a,b,n,m;
bool check( int x, int y)
{
if(x > 0 && x <= a && y > 0 && y<=b)
return true;
return false;
}
int main()
{
bool flag ;
scanf("%d",&k);
while(k--)
{
int x,y;
char s;
flag = false;
scanf("%d %d",&a, &b);
//cout<<"a"<<a<<" "<<"b"<<b<<endl;
for( int i = 1; i<=a; i++)
for( int j = 1; j<=b; j++)
gra[i][j] = -1;
scanf("%d %d",&n, &m);
for( int i = 1; i<=n; i++)
{
cin>>x>>y>>s;
gra[x][y] = i;
ro[i].xx = x;
ro[i].yy = y;
//cout<<"i"<<i<< "y"<<y<<endl;
switch(s)
{
case 'N':
{
ro[i].sta = 0;
break;
}
case 'W':
{
ro[i].sta = 1;
break;
}
case 'S' :
{
ro[i].sta = 2;
break;
}
case 'E' :
{
ro[i].sta = 3;
break;
}
}
//cout<<"input cover"<<endl;
}
for( int i = 0; i<m; i++)
{
int num;
int p;
cin>>num>>s>>p;
// cout<<ro[num].sta<<endl;
if(flag)
continue;
switch (s)
{
case 'L':
{ int rep;
rep = p%4;
ro[num].sta = (ro[num].sta+rep+4)%4;
//cout<<ro[num].sta<<endl;
break;
}
case 'R':
{
int rep;
rep = p%4;
ro[num].sta = (ro[num].sta-rep+4)%4;
//cout<<ro[num].sta<<endl;
break;
}
case 'F':
{
if(ro[num].sta == 0)
{
while(p--)
{
// cout<<p<<" cxvdf"<<endl;
if(check(ro[num].xx,ro[num].yy+1))
{
gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx][ro[num].yy+1]==-1)
{
ro[num].yy++;
//cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx][ro[num].yy+1]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
else if(ro[num].sta == 1)
{
while(p--)
{
if(check(ro[num].xx-1,ro[num].yy))
{
gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx-1][ro[num].yy]==-1)
{
ro[num].xx--;
//cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx-1][ro[num].yy]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
else if(ro[num].sta == 2)
{
while(p--)
{
if(check(ro[num].xx,ro[num].yy-1))
{ gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx][ro[num].yy-1]==-1)
{
ro[num].yy--;
//cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx][ro[num].yy-1]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
else if(ro[num].sta == 3)
{
while(p--)
{
//cout<<"p "<<p<<endl;
if(check(ro[num].xx+1,ro[num].yy))
{ gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx+1][ro[num].yy]==-1)
{
ro[num].xx++;
// cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx+1][ro[num].yy]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
break;
}
}
}
if(!flag)
cout<<"OK"<<endl;
}
}
#include <stdio.h>
#include <string.h>
using namespace std;
int gra[105][105];
struct node
{
int xx,yy,sta;
}ro[105];
int k,a,b,n,m;
bool check( int x, int y)
{
if(x > 0 && x <= a && y > 0 && y<=b)
return true;
return false;
}
int main()
{
bool flag ;
scanf("%d",&k);
while(k--)
{
int x,y;
char s;
flag = false;
scanf("%d %d",&a, &b);
//cout<<"a"<<a<<" "<<"b"<<b<<endl;
for( int i = 1; i<=a; i++)
for( int j = 1; j<=b; j++)
gra[i][j] = -1;
scanf("%d %d",&n, &m);
for( int i = 1; i<=n; i++)
{
cin>>x>>y>>s;
gra[x][y] = i;
ro[i].xx = x;
ro[i].yy = y;
//cout<<"i"<<i<< "y"<<y<<endl;
switch(s)
{
case 'N':
{
ro[i].sta = 0;
break;
}
case 'W':
{
ro[i].sta = 1;
break;
}
case 'S' :
{
ro[i].sta = 2;
break;
}
case 'E' :
{
ro[i].sta = 3;
break;
}
}
//cout<<"input cover"<<endl;
}
for( int i = 0; i<m; i++)
{
int num;
int p;
cin>>num>>s>>p;
// cout<<ro[num].sta<<endl;
if(flag)
continue;
switch (s)
{
case 'L':
{ int rep;
rep = p%4;
ro[num].sta = (ro[num].sta+rep+4)%4;
//cout<<ro[num].sta<<endl;
break;
}
case 'R':
{
int rep;
rep = p%4;
ro[num].sta = (ro[num].sta-rep+4)%4;
//cout<<ro[num].sta<<endl;
break;
}
case 'F':
{
if(ro[num].sta == 0)
{
while(p--)
{
// cout<<p<<" cxvdf"<<endl;
if(check(ro[num].xx,ro[num].yy+1))
{
gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx][ro[num].yy+1]==-1)
{
ro[num].yy++;
//cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx][ro[num].yy+1]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
else if(ro[num].sta == 1)
{
while(p--)
{
if(check(ro[num].xx-1,ro[num].yy))
{
gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx-1][ro[num].yy]==-1)
{
ro[num].xx--;
//cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx-1][ro[num].yy]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
else if(ro[num].sta == 2)
{
while(p--)
{
if(check(ro[num].xx,ro[num].yy-1))
{ gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx][ro[num].yy-1]==-1)
{
ro[num].yy--;
//cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx][ro[num].yy-1]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
else if(ro[num].sta == 3)
{
while(p--)
{
//cout<<"p "<<p<<endl;
if(check(ro[num].xx+1,ro[num].yy))
{ gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx+1][ro[num].yy]==-1)
{
ro[num].xx++;
// cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx+1][ro[num].yy]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
break;
}
}
}
if(!flag)
cout<<"OK"<<endl;
}
}
0 0
- POJ2632
- POJ2632
- poj2632
- POJ2632
- POJ2632
- poj2632
- poj2632
- POJ2632
- poj2632
- poj2632
- poj2632--模拟
- poj2632(模拟)
- Crashing Robots POJ2632
- poj2632 Crashing Robots
- POJ2632--Crashing Robots--模拟
- POJ2632 Crashing Robots
- poj2632--Crashing Robots
- POJ2632 Crashing Robots
- 按照时间戳中的day 聚合排序
- 【健康生活】优秀程序员必备的15大技能
- Tomcat UTF-8 编码设置
- ubuntu 周期性任务管理 --crontab
- Python django web training——(三)我的第一个blog
- POJ2632
- The function that returns the pointer (C Programming)
- 一个奋斗十年的程序员从无到有买系5
- Redis性能调优:保存SNAPSHOT对性能的影响
- 选择排序
- mysql
- Spring Security3 页面 权限标签
- Forests
- iOS: 枚举类型 enum,NS_ENUM,NS_OPTIONS