【HDOJ】4393 Throw nails

水题,优先级队列。

 /* 4393 */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 typedef struct node_t {
int dis, id; node_t() {}
node_t(int dis, int id):
dis(dis), id(id) {} friend bool operator< (const node_t& a, const node_t& b) {
if (a.dis == b.dis)
return a.id > b.id;
return a.dis < b.dis;
} } node_t; const int maxn = ;
const int maxq = ;
int delta[maxq];
priority_queue<node_t> Q[maxq];
int ans[maxn]; void init() {
memset(delta, , sizeof(delta));
rep(i, , maxq)
while (!Q[i].empty())
Q[i].pop();
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int t;
int f, s;
int n; scanf("%d", &t);
rep(tt, , t+) {
scanf("%d", &n);
init();
rep(i, , n+) {
scanf("%d %d", &f, &s);
Q[s].push(node_t(f, i));
} int mx, v, id, tmp;
node_t nd; rep(i, , n) {
mx = -;
rep(j, , ) {
if (!Q[j].empty()) {
nd = Q[j].top();
if (nd.dis+delta[j] > mx) {
mx = delta[j] + nd.dis;
id = nd.id;
v = j;
} else if (nd.dis+delta[j]==mx && nd.id<id) {
id = nd.id;
v = j;
}
}
delta[j] += j;
}
ans[i] = id;
Q[v].pop();
} printf("Case #%d:\n", tt);
printf("%d", ans[]);
rep(i, , n)
printf(" %d", ans[i]);
putchar('\n');
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}
上一篇:HDU 4393 Throw nails


下一篇:单选按钮、复选按钮——axure线框图部件库介绍