题目传送门

  1. /*
  2. 题意:在坐标轴上一群蚂蚁向左或向右爬,问经过ts后,蚂蚁的位置和状态
  3. 思维题:本题的关键1:蚂蚁相撞看作是对穿过去,那么只要判断谁是谁就可以了
  4. 关键2:蚂蚁的相对位置不变 关键3:order数组记录顺序
  5. */
  6. #include <cstdio>
  7. #include <algorithm>
  8. #include <iostream>
  9. #include <cstring>
  10. #include <string>
  11. #include <cmath>
  12. using namespace std;
  13. const int MAXN = 1e4 + ;
  14. const int INF = 0x3f3f3f3f;
  15. const char dir_name[][] = {"L", "Turning", "R"};
  16. struct Ant
  17. {
  18. int pos, dir, id;
  19. bool operator < (const Ant &a) const
  20. {
  21. return pos < a.pos;
  22. }
  23. }pre[MAXN], now[MAXN];
  24. int order[MAXN];
  25. int main(void) //UVA 10881 Piotr's Ants
  26. {
  27. // freopen ("UVA_10881.in", "r", stdin);
  28. int T; int cas = ; int len, t, n;
  29. scanf ("%d", &T);
  30. while (T--)
  31. {
  32. scanf ("%d%d%d", &len, &t, &n);
  33. char ch;
  34. for (int i=; i<=n; ++i)
  35. {
  36. int p, d; char ch;
  37. scanf ("%d %c", &p, &ch);
  38. d = ((ch=='L') ? - : );
  39. pre[i] = (Ant) {p, d, i};
  40. now[i] = (Ant) {p+t*d, d, };
  41. }
  42. sort (pre+, pre++n); //计算相对位置
  43. for (int i=; i<=n; ++i) order[pre[i].id] = i; //输入(输出)的顺序
  44. sort (now+, now++n);
  45. for (int i=; i<n; ++i)
  46. {
  47. if (now[i].pos == now[i+].pos)
  48. now[i].dir = now[i+].dir = ;
  49. }
  50. printf ("Case #%d:\n", ++cas);
  51. for (int i=; i<=n; ++i)
  52. {
  53. int x = order[i];
  54. if (now[x].pos < || now[x].pos > len) puts ("Fell off");
  55. else
  56. {
  57. printf ("%d %s\n", now[x].pos, dir_name[now[x].dir+]);
  58. }
  59. }
  60. puts ("");
  61. }
  62. return ;
  63. }
  64. /*
  65. Case #1:
  66. 2 Turning
  67. 6 R
  68. 2 Turning
  69. Fell off
  70. Case #2:
  71. 3 L
  72. 6 R
  73. 10 R
  74. */

思维题 UVA 10881 Piotr's Ants的更多相关文章

  1. UVA.10881 Piotr's Ants (思维题)

    UVA.10881 Piotr's Ants (思维题) 题意分析 有一根长度为L cm的木棍,上有n只蚂蚁,蚂蚁要么向左爬,要么向右,速度均为1cm/s,若2只蚂蚁相撞,则蚂蚁同时调头.求解第T秒时 ...

  2. POJ 1852 Ants || UVA 10881 - Piotr's Ants 经典的蚂蚁问题

    两题很有趣挺经典的蚂蚁问题. 1.n只蚂蚁以1cm/s的速度在长为L的竿上爬行,当蚂蚁爬到竿子的端点就会掉落.当两只蚂蚁相撞时,只能各自反向爬回去.对于每只蚂蚁,给出距离左端的距离xi,但不知道它的朝 ...

  3. cogs 1456. [UVa 10881,Piotr's Ants]蚂蚁

    1456. [UVa 10881,Piotr's Ants]蚂蚁 ★   输入文件:Ants.in   输出文件:Ants.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述 ...

  4. UVA 10881 Piotr's Ants(等效变换 sort结构体排序)

    Piotr's AntsTime Limit: 2 seconds Piotr likes playing with ants. He has n of them on a horizontal po ...

  5. UVA 10881 - Piotr's Ants【模拟+思维】

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. [ACM_模拟] UVA 10881 Piotr's Ants[蚂蚁移动 数组映射 排序技巧]

    "One thing is for certain: there is no stopping them;the ants will soon be here. And I, for one ...

  7. uva 10881 Piotr's Ants 解题报告

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&pa ...

  8. uva 10881 - Piotr's Ants

    这个题的突破点就在于蚂蚁不能够穿过对方,故相对位置不变: 另外,又可以把蚂蚁看成运动方向不变: 代码: #include<cstdio> #include<algorithm> ...

  9. UVa 10881 Piotr's Ants (等价变换)

    题意:一个长度为L的木棍上有n个蚂蚁,每只蚂蚁要么向左,要么向右,速度为1,当两只蚂蚁相撞时, 它们同时掉头.给定每只蚂蚁初始位置和朝向,问T秒后,每只蚂蚁的状态. 析:刚看到这个题时,一点思路也没有 ...

随机推荐

  1. Android TextView内容过长加省略号

    在Android TextView中有个内容过长加省略号的属性,即ellipsize,用法如下: 在xml中: android:ellipsize = "end" //省略号在结尾 ...

  2. chdoj38 K-partite Graph(补图)

    题意: 若一个无向图G的节点能够分成k(k>=2)个非空集合,对于每对点,当且仅当他们属于不同的集合,存在一条边(ui,vi)连接他们.那么这个图就是一个完全k分图. 现在给出一个n点,m条边的 ...

  3. Redis官方文档资源

    官方文档: 如果要深入研究时,官方提供的文档是最权威的. 英文: https://redis.io/documentation 中文: http://www.redis.cn/documentatio ...

  4. JSP中自动刷新

    以下内容引用自http://wiki.jikexueyuan.com/project/jsp/auto-refresh.html: 细想一个显示在线比赛分数.股市状态或当前交易额的网页.对于所有这种类 ...

  5. MongoDB小结13 - find【2个参数】

    第一个参数 MongoDB使用find来进行查询,查询呢,就是返回一个集合中文档的子集,子集合的范围从0个文档到整个集合. find的第一个参数决定了要返回那些文档,其形式也就一个文档,说明了要执行的 ...

  6. &quot;Simple Factory&quot; vs &quot;Factory Method&quot; vs &quot;Abstract Factory&quot; vs &quot;Reflect&quot;

    ref: http://www.cnblogs.com/zhangchenliang/p/3700820.html 1. "Simple Factory" package torv ...

  7. dataTables 添加行内操作按钮

    在上一篇博客中我们提到了用dataTables 做一个分页表格.今天进一步进阶,做一个行内带操作按钮的表格.效果如图. 记得最基础的实现方式是,我们要在js 中拼接字符串,嵌入一个带按钮的语句.但是现 ...

  8. bzoj 1266 [AHOI2006] 上学路线 route 题解

    转载请注明:http://blog.csdn.net/jiangshibiao/article/details/23989499 [原题] 1266: [AHOI2006]上学路线route Time ...

  9. HDU-3295-An interesting mobile game(BFS+DFS)

    Problem Description XQ,one of the three Sailormoon girls,is usually playing mobile games on the clas ...

  10. C# 实现WEBSOCKET聊天应用示例

    C# 实现WEBSOCKET聊天应用示例 http://blog.163.com/da7_1@126/blog/static/10407267820121016103055506/ 2012-11-1 ...