题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=26579

  考虑两个性质:蚂蚁的相对位置不变,蚂蚁碰撞时相当于对穿而过,然后排两次序就可以了。。

 //STATUS:C++_AC_204MS_3048KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
//#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=1e9+,STA=;
//const LL LNF=1LL<<60;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End struct Node{
int p,d;
bool operator < (const Node& a)const{
return p<a.p;
}
}be[N],af[N];
int L,n; int main()
{
// freopen("in.txt","r",stdin);
int i,j,w,T;
char c;
while(~scanf("%d%d",&L,&n))
{
T=-INF;
for(i=;i<n;i++){
scanf("%d %c",&w,&c);
be[i]=Node{w,c=='L'?-:};
if(c=='L')T=Max(T,w);
else T=Max(T,L-w);
}
for(i=;i<n;i++)
af[i]=Node{be[i].p+be[i].d*T,}; sort(be,be+n);
sort(af,af+n);
for(i=;i<n && af[i].p<;i++);
if(af[i+].p!=L)
printf("The last ant will fall down in %d seconds - started at %d.\n",T,be[i].p);
else printf("The last ant will fall down in %d seconds - started at %d and %d.\n",T,be[i].p,be[i+].p);
}
return ;
}

BNUOJ-26579 Bread Sorting YY的更多相关文章

  1. BNUOJ 26474 Bread Sorting

    /*给出n个原始顺序的数,再给出要排成目标状态顺序,每次从第一个数列中选择三个,把这三个数中最右边的数放在最左边,然后其他两个数右 移一个单位,为你从原始状态能不能排序成目标状态. 本人YY的结论,从 ...

  2. BNUOJ-29364 Bread Sorting 水题

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=29364 题意:给一个序列,输出序列中,二进制1的个数最少的数.. 随便搞搞就行了,关于更多 ...

  3. BNUOJ-29357 Bread Sorting 模拟

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=29357 直接模拟就可以了.. //STATUS:C++_AC_190MS_1884KB # ...

  4. BNUOJ-26474 Bread Sorting 逆序对

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=26474 题意:给一个数列,可以对三个数操作:把最后一个数放到第一个,前两个数后移一位.问最 ...

  5. BNUOJ 26579 Andrew the Ant

    LINK:Andrew the Ant 题意:给一根长度为L的木头,上面有A只蚂蚁[每只蚂蚁给出了初始行走的方向,向左或向右].当两只蚂蚁相碰时,两只蚂蚁就朝相反的方向行走~╮(╯▽╰)╭问的是:最后 ...

  6. NCPC 2012 Bread Sorting

    逆序对数的应用: 逆序对数的写法有,二分,树状数组,分治: 学习一下: 树状数组版: 代码: #include<cstdio> #include<cstring> #inclu ...

  7. BNU 26579 Andrew the Ant 【蚂蚁】

    链接: http://www.bnuoj.com/bnuoj/problem_show.php?pid=26579 http://www.bnuoj.com/bnuoj/contest_show.ph ...

  8. bnuoj 27874 "Center" of [p]erimeter midpoints(计算几何)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=27874 [题意]: 给你一个三角形三个顶点的坐标ABC,三角形各边取一点DEF,将三角形周长平均分割 ...

  9. BNUOJ 12756 Social Holidaying(二分匹配)

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=12756 Social Holidaying Time Limit: 3000ms Memo ...

随机推荐

  1. uva 10271

    DP  状态转移方程 dp[i][j] = min(dp[i-1][j], dp[i-2][j-1] + w)) dp[i][j] 指的是前i个筷子组成j组所花费的最小值 考虑第i个筷子是否参与第j组 ...

  2. 跨平台查询文件时间,如果超过7天,删除该文件(windows和linxu测试过)

    windows调用的是_stat函数,linux调用的是stat函数. #include <time.h> #include <sys/types.h> #include &l ...

  3. 面试大总结之二:Java搞定面试中的二叉树题目

    package BinaryTreeSummary; import java.util.ArrayList; import java.util.Iterator; import java.util.L ...

  4. 214. Shortest Palindrome

    题目: Given a string S, you are allowed to convert it to a palindrome by adding characters in front of ...

  5. 转:JavaScript中函数与对象的关系

    来自:http://www.nowamagic.net/javascript/js_RelationOfFunctionAndObject.php 在ajax兴起以前,很多人写JavaScript可以 ...

  6. 【HDOJ】4605 Magic Ball Game

    思路1:树状数组+离线处理,对所有的w离散化处理,边dfs边使用树状数组更新左右w的情况.思路2:主席树,边bfs边建树.结点信息存储cnt,然后在线查询.树状数组. /* 4605 */ #incl ...

  7. php 类 成员变量 $this->name='abc'

    <?php class test { public function getName() { $this->name='abc'; echo $this->name; } }$a=n ...

  8. [原]Unity3D深入浅出 - 物理引擎之碰撞体(Colliders)

    通常Colliders会与Rigidbody一起使用,没有添加碰撞体的刚体会彼此相互穿过. 常用碰撞体有以下几种: Box Collider:盒子碰撞体,是一个立方体外形的碰撞体,可调整为不同大小的长 ...

  9. UVa 1152 (中途相遇法) 4 Values whose Sum is 0

    题意: 要从四个数组中各选一个数,使得这四个数之和为0,求合法的方案数. 分析: 首先枚举A+B所有可能的值,排序. 然后枚举所有-C-D的值在其中用二分法查找. #include <cstdi ...

  10. SCOI2007修车

    这样也行?这构图把我惊呆了: 把每个工人拆成N个点.记为A[i,j]表示第i个工人修倒数第j辆车. 每个车跟所有N*M个工人拆出的点连边.流量为1,费用为time[i,j]*k. 源和每辆车连边,N* ...