UVa 10881 Piotr's Ants ——思路题
2017-05-26 18:59
447 查看
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 10000 + 5; const char dirName[][10] = {"L", "Turning", "R"}; struct Art { int id, pos, sta; bool operator < (const Art &a) const { return pos < a.pos; } }a1[maxn], a2[maxn]; int order[maxn]; int main() { int k; scanf("%d", &k); for (int kase = 1; kase <= k; kase++) { int L, T, n; printf("Case #%d:\n", kase); scanf("%d %d %d", &L, &T, &n); for (int i = 0; i < n; i++) { int pos, sta; char c; scanf("%d %c", &pos, &c); sta = (c == 'L' ? -1 : 1); a1[i] = (Art){i, pos, sta}; a2[i] = (Art){0, pos + T * sta, sta}; } sort(a1, a1 + n); for (int i = 0; i < n; i++) order[a1[i].id] = i; sort(a2, a2 + n); for (int i = 0; i < n - 1; i++) { if (a2[i].pos == a2[i + 1].pos) a2[i].sta = a2[i + 1].sta = 0; } for (int i = 0; i < n; i++) { int a = order[i]; if (a2[a].pos < 0 || a2[a].pos > L) printf("Fell off\n"); else printf("%d %s\n", a2[a].pos, dirName[a2[a].sta + 1]); } printf("\n"); } return 0; }
相关文章推荐
- UVA - 10881-Piotr's Ants-思路题/模拟
- UVA 10881 Piotr's Ants
- UVa 10881 - Piotr's Ants
- UVa10881-Piotr's Ants
- UVA.10881 Piotr's Ants (思维题)
- uva10881 - Piotr's Ants (等效变换)
- UVa - 10881 - Piotr's Ants
- UVA 10881 Piotr's Ants
- Piotr's Ants UVA - 10881
- UVA_10881 - Piotr's Ants
- UVa 10881 - Piotr's Ants
- UVA10881----Piotr's Ants
- Uva 10881 - Piotr's Ants( 转换思维 )
- Piotr's Ants(Uva 10881)
- 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)