比赛 20160419s 评测结果 WWWWWWWWWW
题目名称 扑克游戏 最终得分 0
用户昵称 KZNS 运行时间 0.233 s
代码语言 C++ 内存使用 0.35 MiB
提交时间 2016-04-19 09:31:11
显示代码纯文本
//KZNS
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
//
ifstream fin ("poker.in");
ofstream fout ("poker.out");
class poi {
public:
	int a, v, u;
	poi(){}
	poi(int a, int v, int u) :
	a(a), v(v), u(u) {}
	inline bool operator () (poi x, poi y) {
		if ((x.a - y.a) == (y.v - x.v)*x.u)
			return x.v > y.v;
		else
			return (x.a - y.a) > (y.v - x.v)*x.u;
	}
};
bool operator == (poi x, poi y) {
	if (x.a == y.a && x.v == y.v)
		return true;
	return false;
}
const int Nmax = 10003;
//
int N;
int A[Nmax];
int ed = 0;
priority_queue<poi, vector<poi>, poi> Q[14];
priority_queue<poi, vector<poi>, poi> D[14];
//
inline void fir() {
	fin >> N;
	for (int i = 0; i < N; i++)
		fin >> A[i];
}
inline void dlin(int a, int v) {
	for (int i = 1; i <= 13; i++)
		D[i].push(poi(a, v, i));
}
inline void adin(int a, int v) {
	for (int i = 1; i <= 13; i++)
		Q[i].push(poi(a, v, i));
}
inline void dlt(int t) {
	while ((!D[t].empty())&&(D[t].top() == Q[t].top())) {
		D[t].pop();
		Q[t].pop();
	}
}
inline void work() {
	int u;
	poi poiu;
	for (int i = N-1; i >= 0 && i >= N-2; i--) {
		u = A[i];
		adin(u, 1);
		ed += u;
	}
	for (int i = N-3; i >= 0; i--) {
		u = A[i];
		dlt(u);
		poiu = Q[u].top();
		dlin(poiu.a, poiu.v);
		adin(poiu.a, poiu.v+1);
		adin(u, poiu.v+1);
		ed += poiu.a + u*(poiu.v+1);
	}
}
//
int main() {
	fir();
	sort(A, A+N);
	work();
	fout << ed;
	return 0;
}
//UBWH