Piotr's Ants UVa 10881
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#define maxn 10005
#define L -1
#define R 1
#define fell 10
#define Turning -10
#define On 0; using namespace std;
struct ants{
int location;
int direction;
int inputorder;
int state;
bool operator < (const ants& a) const{
return location <a.location;
}
}Ant[maxn]; int main(){
//if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);} int n,l,T;
int N;
cin>>N;
for(int test=;test<=N;test++){
cin>>l>>T>>n;
int a;
char ch;
for(int i=;i<=n;i++){
cin>>a>>ch; if(ch == 'R') Ant[i].direction = R;
else Ant[i].direction = L;
Ant[i].location = a;
Ant[i].inputorder = i;
}
sort(Ant+,Ant+n+);
int order[maxn];
for(int i=;i<=n;i++){
order[Ant[i].inputorder] = i;
} for(int i=;i<=n;i++) Ant[i].location += T * Ant[i].direction; sort(Ant+,Ant+n+); for(int i=;i<=n;i++)
if(Ant[i].location < || Ant[i].location > l)
Ant[i].state = fell;
else if(Ant[i].location == Ant[i+].location && i < n) {
Ant[i].state = Ant [i+].state = Turning;
i++;
}
else
Ant[i].state = On;
printf("Case #%d:\n",test); for(int i=;i<=n;i++){
int j = order[i];
if(Ant[j].state == fell) printf("Fell off\n");
else if(Ant[j].state == Turning){
printf("%d Turning\n",Ant[j].location);
}
else
printf("%d %c\n",Ant[j].location,Ant[j].direction == R ? 'R' : 'L'); }
printf("\n");
}
}
Piotr's Ants UVa 10881的更多相关文章
- POJ 1852 Ants || UVA 10881 - Piotr's Ants 经典的蚂蚁问题
两题很有趣挺经典的蚂蚁问题. 1.n只蚂蚁以1cm/s的速度在长为L的竿上爬行,当蚂蚁爬到竿子的端点就会掉落.当两只蚂蚁相撞时,只能各自反向爬回去.对于每只蚂蚁,给出距离左端的距离xi,但不知道它的朝 ...
- UVA.10881 Piotr's Ants (思维题)
UVA.10881 Piotr's Ants (思维题) 题意分析 有一根长度为L cm的木棍,上有n只蚂蚁,蚂蚁要么向左爬,要么向右,速度均为1cm/s,若2只蚂蚁相撞,则蚂蚁同时调头.求解第T秒时 ...
- 【UVa 10881】Piotr's Ants
Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...
- 思维题 UVA 10881 Piotr's Ants
题目传送门 /* 题意:在坐标轴上一群蚂蚁向左或向右爬,问经过ts后,蚂蚁的位置和状态 思维题:本题的关键1:蚂蚁相撞看作是对穿过去,那么只要判断谁是谁就可以了 关键2:蚂蚁的相对位置不变 关键3:o ...
- cogs 1456. [UVa 10881,Piotr's Ants]蚂蚁
1456. [UVa 10881,Piotr's Ants]蚂蚁 ★ 输入文件:Ants.in 输出文件:Ants.out 简单对比时间限制:1 s 内存限制:128 MB [题目描述 ...
- 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 ...
- 【巧妙的模拟】【UVA 10881】 - Piotr's Ants/Piotr的蚂蚁
</pre></center><center style="font-family: Simsun;font-size:14px;"><s ...
- 10881 - Piotr's Ants(排序)
题目链接:10881 - Piotr's Ants 题目大意:在一个长为L的木棒上有n只蚂蚁,给出蚂蚁的初始位置以及方向,问说移动T秒后各个蚂蚁的位置以及状态,如果两只蚂蚁在移动的过程中相撞,则会同时 ...
- 10881 - Piotr's Ants
Problem D Piotr's Ants Time Limit: 2 seconds "One thing is for certain: there is no stopping th ...
随机推荐
- oracle触发器调试
1.如下图位置点击触发器,会出现调试窗口 2.执行编译并调试 3.点击小虫,将画红位置,加入会触发此触发器的语句.如果触发器执行成功,不会出现第4个图,不成功,会出现数据调试信息,具体报错位置会定位到 ...
- CI 笔记(1)
1. 下载CI,官方网站,目前3.x版本已经更新,2.2.6版本为2.x版本的最后的一个版本.为了和视频教材一致,使用CI 2.x版本 2. 目录结构,从application里面的,controll ...
- iOS-NSSDate的使用
取当前时间的秒数 NSTimeInterval time = [[NSDate date] timeIntervalSince1970];long long int date = (long long ...
- java_设计模式_观察者模式_Observer Pattern(2016-07-27)
看了好几篇文章,最终还是觉得<Head First 设计模式>举得例子比较符合观察者模式. 观察者模式概述: 观察者模式有时被称作发布/订阅模式,它定义了一种一对多的依赖关系,让多个观察者 ...
- Problem 1108 - 淼·诺贝尔
#include<iostream> #include<vector> #include<algorithm> using namespace std; struc ...
- SGU 144.Meeting
题目: 两支地区ACM比赛的队伍决定为了国际决赛而在一起集训. 他们约定在某天的 X 时到 Y 时的某一时刻相会. 但由于他们很少按时到 (有的队伍比赛那天都会迟到), 他们没有设定一个确切的相遇时间 ...
- codeforces 165D.Beard Graph 解题报告
题意: 给一棵树,树的每条边有一种颜色,黑色或白色,一开始所有边均为黑色,有两个操作: 操作1:将第i条边变成白色或将第i条边变成黑色. 操作2 :询问u,v两点之间仅经过黑色变的最短距离. 树链剖分 ...
- 借助Q.js学习javascript异步编程。
金字塔式 //add1 function step1(n, callback) { setTimeout(function(){ callback.call(null, n + 1); }, 100) ...
- Visual Studio 2013 在使用 MVC5 无智能提示
关于 Visual Studio 2013 在使用 MVC5 无智能提示的问题,类库无法正常识别,连最基本的关键字提示都没有了,类变色也没有了,所有的关键字代码,类名,方法成员名都要全部手动敲 原因: ...
- 【开源】前端练手笔记,Chrome扩展应用程序(html+CSS+JS) (1)
项目名称:github-notification 项目地址:https://github.com/WQTeam/github-notification 说明:本人打算抽时间学习前端(html + cs ...