codeforce #322C Developing Skills (优先队列)
来源:互联网 发布:linux vi 删除字符 编辑:程序博客网 时间:2024/06/14 16:50
题目:http://codeforces.com/contest/581/problem/C
题意:玩游戏,你的角色有n项技能,各项技能的值为a1,a2...an(0 <= a <= 100),总分为 a1/10 + a2/10 + ... + an / 10(a/10向下取整)。现在你有k分可以用来增加技能值,问,能获得的最大总分是多少。不一定要用完k分。
思路:如果一项技能值ai % 10 最小,那么把分加给它效果最明显。所以用一个结构保存各项技能的 ai 和 ai % 10,每次加分取出 ai % 10 小的加分,用优先队列 ai % 10 小的排在前面。复杂度O(k*logn)。
#include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>#include <stdlib.h>#include <queue>#define INF 0x7fffffff#define MOD 1000000007using namespace std;typedef long long ll;struct skill{ int x, l; bool operator < (const skill& rhs) const { return l > rhs.l; }}cur;priority_queue<skill> que;int main(){ #ifdef LOCAL freopen("data.in", "r", stdin); #endif int n, k; while(scanf("%d%d", &n, &k) != EOF) { while(!que.empty()) que.pop(); int x, ans = 0; for(int i = 0; i < n; i++) { scanf("%d", &x); ans += x / 10; cur.x = x; cur.l = 10 - x % 10; if(x < 100) que.push(cur); } while(k && !que.empty()) { cur = que.top(); que.pop(); //printf("cur:%d %d k=%d\n", cur.x, cur.l, k); if(cur.l <= k) { ans++; k -= cur.l; cur.x += cur.l; cur.l = 10; if(cur.x < 100) que.push(cur); } else break; } printf("%d\n", ans); } return 0;}
0 0
- codeforce #322C Developing Skills (优先队列)
- Developing Skills(优先队列)
- C. Developing Skills (CF Round #322 (Div.2) 贪心)
- Codeforces Round #322 C Developing Skills
- codefoces 581C Developing Skills(贪心)
- codeforces 581-C. Developing Skills(贪心)
- Codeforces 581C Developing Skills
- codeforces 581C Developing Skills
- cf 591 C. Developing Skills
- CF 581C Developing Skills
- coderforce 581C. Developing Skills
- codeforces 581C Developing Skills
- CodeForces 581C Developing Skills
- Codeforces-581C-Developing Skills
- CF#322-C-Developing Skills-模拟大水题
- Codeforces Round #322 (Div. 2)C. Developing Skills
- Codeforces Round #322 (Div. 2)C. Developing Skills
- Code Forces 581 C. Developing Skills(贪心)
- linux命令行
- replace与replaceAll的区别
- Android事件分发机制完全解析,带你从源码的角度彻底理解(上)
- android 更改数据库路径 apk卸载 数据库中的数据不会丢失
- UIWebView与JavaScript(JS) 回调交互
- codeforce #322C Developing Skills (优先队列)
- 常规保养配件信息查询api接口
- C3P0连接池配置
- 通信系统软件开发-1、几个概念的区别
- 机器人点灯(light-bot)2.0通关攻略(二)——条件
- MySQL 高可用MMM
- tomcat调优
- SQL Server2008定期清理日志
- iOS开发真机调试和证书相关的一些坑