思维题 UVA 10881 Piotr's Ants
2015-07-14 10:16
585 查看
题目传送门
/* 题意:在坐标轴上一群蚂蚁向左或向右爬,问经过ts后,蚂蚁的位置和状态 思维题:本题的关键1:蚂蚁相撞看作是对穿过去,那么只要判断谁是谁就可以了 关键2:蚂蚁的相对位置不变 关键3:order数组记录顺序 */ #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> #include <string> #include <cmath> using namespace std; const int MAXN = 1e4 + 10; const int INF = 0x3f3f3f3f; const char dir_name[][10] = {"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 = 0; int len, t, n; scanf ("%d", &T); while (T--) { scanf ("%d%d%d", &len, &t, &n); char ch; for (int i=1; i<=n; ++i) { int p, d; char ch; scanf ("%d %c", &p, &ch); d = ((ch=='L') ? -1 : 1); pre[i] = (Ant) {p, d, i}; now[i] = (Ant) {p+t*d, d, 0}; } sort (pre+1, pre+1+n); //计算相对位置 for (int i=1; i<=n; ++i) order[pre[i].id] = i; //输入(输出)的顺序 sort (now+1, now+1+n); for (int i=1; i<n; ++i) { if (now[i].pos == now[i+1].pos) now[i].dir = now[i+1].dir = 0; } printf ("Case #%d:\n", ++cas); for (int i=1; i<=n; ++i) { int x = order[i]; if (now[x].pos < 0 || now[x].pos > len) puts ("Fell off"); else { printf ("%d %s\n", now[x].pos, dir_name[now[x].dir+1]); } } puts (""); } return 0; } /* Case #1: 2 Turning 6 R 2 Turning Fell off Case #2: 3 L 6 R 10 R */
相关文章推荐
- Linux IO工具 iotop备择方案iopp
- 物联网,从百姓生活开始
- Uva 10881 - Piotr's Ants
- 机器视觉在物联网中的应用
- C#“猜猜看”——物联网工程1122 黄炜彬
- linux iotop安装
- linux iotop安装
- 用AudioTrack进行音频录制传输
- Wind River Opens IoT Marketplace for VxWorks OS
- 物联网WiFi/BT/ZigBee芯片
- 『智能物联网』QQ群 419130936
- 物联网操作系统HelloX开发者入门指南
- 物联网操作系统HelloX开发者入门指南
- 物联网操作系统HelloX开发者入门指南
- Google输了官司,物联网恐怕也不能用Java了吧
- ARM--mbed物联网操作系统------初探
- 嵌入式物联网开发平台解读---之RTOS
- 物联网探步--工具篇之安装qvb
- 使用AudioTrack进行音频播放
- 【HDU 4609】3-idiots(FFT)