UVa 10881Piotr's Ants【思维】
来源:互联网 发布:网络延迟怎么解决 编辑:程序博客网 时间:2024/06/05 19:29
题目链接
对于每个蚂蚁来说,他相对于其他蚂蚁的位置是固定的,赶超前面或者被后面的赶超都是要回头的,所以,假设木棒无限长,位于第一位的永远在第一位,第二位的永远在第二位。同时每两个碰头的蚂蚁其实就是类似于交换了身份继续前进。所以,先不管他们的碰头,就让每个沿着路线继续走下去。由前面的可以知道,每个蚂蚁的最终状态的位置排列的顺序就是一开始蚂蚁的编号。
#include <map>#include <set>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <iostream>#include <stack>#include <cmath>#include <string>#include <vector>#include <cstdlib>//#include <bits/stdc++.h>//#define LOACL#define space " "#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;typedef unsigned long long UL;//typedef __int64 Int;typedef pair<int, int> PAI;const int INF = 0x3f3f3f3f;const double ESP = 1e-5;const double PI = acos(-1.0);const int MOD = 1e9 + 7;const int MAXN = 10000 + 10;struct ant { int dic; int s, e; int id;} data[MAXN];int f[MAXN];char str[][10] = {"L", "Turning", "R", "Fell off"};bool cmp(ant x, ant y) {return x.e < y.e;}bool cmp1(ant x, ant y) {return x.s < y.s;}int main() { int T; char s[10]; scanf("%d", &T); int Kcase = 0; while (T--) { int L, t, N; scanf("%d%d%d", &L, &t, &N); for (int i = 0; i < N; i++) { scanf("%d%s", &data[i].s, s); data[i].dic = (s[0] == 'R'? 1: -1); data[i].id = i; data[i].e = data[i].s + data[i].dic*t; } sort(data, data + N, cmp1); for (int i = 0; i < N; i++) f[data[i].id] = i; sort(data, data + N, cmp); for (int i = 0; i < N; i++) { if (data[i].e < 0 || data[i].e > L) data[i].dic = 2; else if (i != 0 && data[i].e == data[i - 1].e) data[i].dic = data[i - 1].dic = 0; } printf("Case #%d:\n", ++Kcase); for (int i = 0; i < N; i++) { int u = f[i]; int v = data[u].dic; if (v == 2) printf("Fell off\n"); else printf("%d %s\n", data[u].e, str[v+1]); } printf("\n"); } return 0;}
0 0
- UVA 10881 Piotr's Ants (思维)
- Uva 10881 - Piotr's Ants( 转换思维 )
- UVA 10881 - Piotr's Ants(思维题)
- UVA 10881 Piotr's Ants(思维题)
- UVA.10881 Piotr's Ants (思维题)
- UVa 10881Piotr's Ants【思维】
- UVa --- 10881 Piotr's Ants 【思维】
- uva 10881 - Piotr's Ants (思维,3级)
- Uva 10881 Piotr's Ants (模拟+思维)
- UVA 10881 - Piotr's Ants(思维转换)
- UVa - 10881 - Piotr's Ants
- uva 10881 - Piotr's Ants
- Uva-10881-Piotr's Ants
- uva 10881 - Piotr's Ants
- UVa 10881 Piotr's Ants
- UVA 10881 Piotr's Ants
- Piotr's ants UVA 10881
- UVa 10881 - Piotr's Ants
- JS(JQ)实现带动画的回到顶部效果
- 写给养花小白的水培小教程
- java mina的使用
- Java Script里Ajax操作
- 初识线程
- UVa 10881Piotr's Ants【思维】
- ngrok设置开机自启动
- javaSE_8系列博客——Java语言的特性(二)--高级语言的基础知识(5)-- 运算符
- JQuery ajax操作
- WebService笔记
- Android 数据存储和访问----商品展示
- JavaScript学习笔记25-新建一个我们自己的对象
- SSH做项目时经验总结 (3)
- Dynamics CRM plugin调试的第三种方式