HDU 4393 Throw nails
因为第i个人第1秒走的距离Fi满足0 <= Fi <= 500,所以502秒后所有人的名次都不会再变化。所以,前502秒可以暴搜,剩下的只要排序后直接输出即可。[cpp]
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
const int maxn = 50010;
int t, n;
struct Player {
int k, s, id, dis;
};
Player p[maxn];
bool cmp(Player p1, Player p2)
{
if (p1.k != p2.k) {
return p1.k < p2.k;
}
if (p1.dis != p2.dis) {
return p1.dis > p2.dis;
}
return p1.id < p2.id;
}
int main()
{
scanf("%d", &t);
for (int cas = 1; cas <= t; ++cas) {
scanf("%d", &n);
int f, s;
p[0].dis = (1 << 30);
p[0].k = -1;
p[0].id = -1;
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &f, &s);
p[i].k = 1;
p[i].s = s;
p[i].id = i;
p[i].dis = f;
}
printf("Case #%d:\n", cas);
int Max = -1, idx;
for (int i = 1; i <= n; ++i) {
if (p[i].dis > Max) {
Max = p[i].dis;
idx = i;
}
}
p[idx].k = -1;
printf("%d", idx);
for (int i = 2; i <= min(n, 502); ++i) {
int Max = -1, idx;
for (int j = 1; j <= n; ++j) {
if (p[j].k == -1) continue;
p[j].dis += p[j].s;
if (p[j].dis > Max) {
Max = p[j].dis;
idx = j;
}
}
p[idx].k = -1;
printf(" %d", idx);
}
sort(p, p + n + 1, cmp);
for (int i = 503; i <= max(502, n); ++i) {
printf(" %d", p[i].id);
}
printf("\n");
}
return 0;
}
补充:软件开发 , C++ ,