http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&page=show_problem&problem=1822
题意:一根长为L的木棒上有n只蚂蚁左右移动,1秒1个单位长度,碰撞后反向移动,问T秒后蚂蚁的位置与方向。
思路:碰撞后反方向和直接穿过相对位置来说是一样的,他们在木棒上的相对顺序是不变的。
#include <iostream>
#include <algorithm>
using namespace std;
#define MAXN 10010
struct Ant
{
int inputID; //记录输入的顺序
int pos; //起始位置
int direction; //方向 左-1,转身0,右1
const bool operator < (const struct Ant &a) const
{
return po