您的位置:首页 > 大数据 > 物联网

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: