题目传送门

 /*
题意:在坐标轴上一群蚂蚁向左或向右爬,问经过ts后,蚂蚁的位置和状态
思维题:本题的关键1:蚂蚁相撞看作是对穿过去,那么只要判断谁是谁就可以了
关键2:蚂蚁的相对位置不变 关键3:order数组记录顺序
*/
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
const char dir_name[][] = {"L", "Turning", "R"};
struct Ant
{
int pos, dir, id;
bool operator < (const Ant &a) const
{
return pos < a.pos;
}
}pre[MAXN], now[MAXN];
int order[MAXN]; int main(void) //UVA 10881 Piotr's Ants
{
// freopen ("UVA_10881.in", "r", stdin); int T; int cas = ; int len, t, n;
scanf ("%d", &T);
while (T--)
{
scanf ("%d%d%d", &len, &t, &n);
char ch;
for (int i=; i<=n; ++i)
{
int p, d; char ch;
scanf ("%d %c", &p, &ch);
d = ((ch=='L') ? - : );
pre[i] = (Ant) {p, d, i};
now[i] = (Ant) {p+t*d, d, };
} sort (pre+, pre++n); //计算相对位置
for (int i=; i<=n; ++i) order[pre[i].id] = i; //输入(输出)的顺序 sort (now+, now++n);
for (int i=; i<n; ++i)
{
if (now[i].pos == now[i+].pos)
now[i].dir = now[i+].dir = ;
} printf ("Case #%d:\n", ++cas);
for (int i=; i<=n; ++i)
{
int x = order[i];
if (now[x].pos < || now[x].pos > len) puts ("Fell off");
else
{
printf ("%d %s\n", now[x].pos, dir_name[now[x].dir+]);
}
} puts ("");
} return ;
} /*
Case #1:
2 Turning
6 R
2 Turning
Fell off Case #2:
3 L
6 R
10 R
*/

思维题 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. 【JZOJ4857】Tourist Attractions(Bitset)

    题意:给定一个n个点的无向图,求这个图中有多少条长度为4的简单路径. n<=1500 思路: #include<map> #include<set> #include&l ...

  2. MongoDB C#驱动

    烟波钓徒 MongoDB C#驱动 http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial 笔记 首先下载驱动.驱动有两个文件 Mongo ...

  3. spring mvc随便接收list<objeect>参数

    在后台设定一个类,PersonList类: public class PersonList {private List<User> user; public List<User> ...

  4. Spring中JavaConfig特性

    从Spring3開始,增加了JavaConfig特性.JavaConfig特性同意开发人员不必在Spring的xml配置文件里定义bean,能够在Java Class中通过凝视配置bean,假设你讨厌 ...

  5. HDU 2870 Largest Submatrix (单调栈)

    http://acm.hdu.edu.cn/showproblem.php? pid=2870 Largest Submatrix Time Limit: 2000/1000 MS (Java/Oth ...

  6. 【Akka】Actor模型探索

    Akka是什么 Akka就是为了改变编写高容错性和强可扩展性的并发程序而生的.通过使用Actor模型我们提升了抽象级别,为构建正确的可扩展并发应用提供了一个更好的平台.在容错性方面我们採取了" ...

  7. Mahout贝叶斯算法拓展篇3---分类无标签数据

    代码測试环境:Hadoop2.4+Mahout1.0 前面博客:mahout贝叶斯算法开发思路(拓展篇)1和mahout贝叶斯算法开发思路(拓展篇)2 分析了Mahout中贝叶斯算法针对数值型数据的处 ...

  8. UVA 1397 - The Teacher&#39;s Side of Math(高斯消元)

    UVA 1397 - The Teacher's Side of Math 题目链接 题意:给定一个x=a1/m+b1/n.求原方程组 思路:因为m*n最多20,全部最高项仅仅有20.然后能够把每一个 ...

  9. tt1

    DIm #include iostream.h#include iostream.h# #include iostream.h http://www.cnblogs.com/cmt/archive/2 ...

  10. APICloud平台的融云2.0集成

    融云2.0的官方文档地址:http://docs.apicloud.com/端API/开放SDK/rongCloud2 项目须要IM模块,最后还是选择了融云.在iOS原生开发中,融云sdk集成了聊天界 ...