题意:一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的名字。
题解:1.一种计算机编程的普遍思想,就是变化不一定需要体现出来、
2.这道题就是首先蚂蚁碰撞调头,但是在编程中不一定需要体现出来,碰撞调头可以等效成擦肩而过
3.还有就是蚂蚁的相对顺序总是固定的,我用的方法就是假设这条线无限长,蚂蚁可以无限制的走下去,然后
找到那个最后出现在边界线的蚂蚁,并通过相对顺序算出他是哪个蚂蚁
总结:不知为何,g++提交就re了c++就过了
<pre name="code" class="cpp">#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAXN 255
#define MAXM 32005
struct Pos
{
double pos;
char s[MAXN],dir[4];
bool operator < (const struct Pos & a)const{
return pos < a.pos;
}
}pos[MAXM];
double last[MAXM];
int main()
{
int n;
double l,v,len;
while(scanf("%d",&n),n)
{
scanf("%lf%lf",&l,&v);
double maxn = 0;
for(int i = 0;i < n;i++)
{
scanf("%s %lf %s",&pos[i].dir,&pos[i].pos,&pos[i].s);
if(pos[i].dir[0] == 'p' || pos[i].dir[0] == 'P')
len = l - pos[i].pos;
else len = pos[i].pos;
maxn = max(maxn,len);
}
bool zero = false;
for(int i = 0;i < n;i++)
{
if(pos[i].dir[0] == 'p' || pos[i].dir[0] == 'P')
last[i] = pos[i].pos + maxn;
else last[i] = pos[i].pos - maxn;
if(last[i] == 0)zero = true;
}
int ind = 0,limit = l;
if(zero)limit = 0;
for(int i = 0;i < n;i++)
{
if(last[i] < limit)
ind++;
}
printf("%13.2lf %s\n",(int)(maxn / v * 100) / 100.0,pos[ind].s);
}
}