poj2380

//============================================================================
// Name        : 2380.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <stdio.h>
#include <algorithm>
#include <set>
#include <queue>
#define N 500000
using namespace std;

typedef struct node {
	int id1;
	int id2;
	int value;
} Node;

struct comp {
	bool operator()(const Node& a, const Node& b) {
		if (a.id1 != b.id1)
			return a.id1 > b.id1;
		return a.id2 > b.id2;
	}
};

int com(const Node& a, const Node& b) {
	if (a.id1 != b.id1)
		return a.id1 - b.id1;
	return a.id2 - b.id2;
}

vector<Node> data;
set<int> sids;

int main() {
	int n;
	scanf("%d", &n);
	Node nd;
	for (int i = 0; i < n; i++) {
		scanf("%d %d %d", &nd.id2, &nd.id1, &nd.value);
		data.push_back(nd);
		sids.insert(nd.id2);
	}
	int* ctid= new int[sids.size()];
	int column = 0;
	printf("-1");
	for (set<int>::iterator it2 = sids.begin(); it2 != sids.end(); ++it2) {
		ctid[column++] = *it2;
		printf(" %d", *it2);
	}
	puts("");
	priority_queue<Node, vector<Node>, comp> q(data.begin(), data.end());
	Node last = q.top();
	q.pop();
	int rowid = last.id1;
	int c = 0;
	printf("%d", rowid);
	while (!q.empty()) {
		Node top = q.top();
		q.pop();
		if (com(top, last) == 0) {
			last.value += top.value;
		} else {
			if (rowid != last.id1) {
				rowid = last.id1;
				while (c < column) {
					c++;
					printf(" 0");
				}
				c = 0;
				puts("");
				printf("%d", rowid);
			}
			int nc = last.id2;
			while (ctid[c] < nc) {
				c++;
				printf(" 0");
			}
			c++;
			printf(" %d", last.value);
			last = top;
		}
	}
	if (rowid != last.id1) {
		rowid = last.id1;
		while (c < column) {
			c++;
			printf(" 0");
		}
		c = 0;
		puts("");
		printf("%d", rowid);
	}
	int nc = last.id2;
	while (ctid[c] < nc) {
		c++;
		printf(" 0");
	}
	c++;
	printf(" %d", last.value);
	while (c < column) {
		c++;
		printf(" 0");
	}
	puts("");
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值