目录:
题目:
题意:
给出若干个蚂蚁的坐标,以及移动的方向,求在无限时间后,还存活这的蚂蚁有多少只
分析:
其实完全是道大模拟题,所以我们完全不用虚,当然我们的移动得按0.5个单位长度移动(因为可能在中途相遇)
其他的就很简单了,只用简单的一个判断就行了,最后再将还活着的统计下就可以啦
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
inline double read() {
double d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
int n,ans,f;
double t=2005;
char c[51];
struct node{
double x,y;
char w;
}a[51];
int check(int x)
{
if (a[x].w=='E'||a[x].w=='N'||a[x].w=='W'||a[x].w=='S') return 1;
return 0;
}
int main()
{
scanf("%d",&n);
scanf("%s",c);
for (int i=1;i<=n;i++)
a[i].w=c[i-1];
for (int i=1;i<=n;i++)
a[i].x=read(),a[i].y=read();
while (t-=0.5)//0.5移动
{
for (int i=1;i<=n;i++)
{
if (a[i].w=='N') {a[i].y+=0.5;continue;};
if (a[i].w=='E') {a[i].x+=0.5;continue;};
if (a[i].w=='S') {a[i].y-=0.5;continue;};
if (a[i].w=='W') {a[i].x-=0.5;continue;};
}
for (int i=1;i<n;i++)//将相遇的标记死亡
{
f=0;
//'\0'为死亡
for (int j=i+1;j<=n;j++) if(a[i].x==a[j].x&&a[i].y==a[j].y&&check(i)&&check(j)) a[j].w='\0',f=1;
if (f) a[i].w='\0';
}
}
for (int i=1;i<=n;i++)
ans+=check(i);
printf("%d",ans);
return 0;
}