码迷,mamicode.com
首页 > 其他好文 > 详细

uva 11691

时间:2014-08-19 12:34:14      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:blog   使用   os   io   for   ar   div   amp   

贪心 ~~ 

使用优先队列

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <stack>
#include <vector>
#include <sstream>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#define FFI freopen("in.txt", "r", stdin)
#define maxn 1010
#define INF 0x3f3f3f3f
#define inf 1000000000
#define mod 1000000007
#define ULL unsigned long long
#define LL long long
#define _setm(houge) memset(houge, INF, sizeof(houge))
#define _setf(houge) memset(houge, -1, sizeof(houge))
#define _clear(houge) memset(houge, 0, sizeof(houge))
using namespace std;

const int N = (1<<20)+5;
const int M = 30;

int n;
priority_queue <int> Q;

int main () {
	// FFI;
	int t;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		for(int i = 0; i < n; ++ i) {
			int a;
			scanf("%d", &a);
			Q.push(a);
		}
		if(n == 1) {
			printf("%d\n", Q.top());
			Q.pop();
			continue;
		}
		int ans = 0;
		while(!Q.empty()) {
			int a = Q.top();
			Q.pop();
			int b = Q.top();
			Q.pop();
			if(Q.empty()) {
				ans += a+1;
				break;
			}
			ans += b;
			Q.push(a-b+1);
		}
		printf("%d\n", ans);
	}
	return 0;
}

  

uva 11691,布布扣,bubuko.com

uva 11691

标签:blog   使用   os   io   for   ar   div   amp   

原文地址:http://www.cnblogs.com/avema/p/3921552.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!