SGU 548 Dragons and Princesses
来源:互联网 发布:ods直播软件 编辑:程序博客网 时间:2024/05/19 13:42
题意:
n个格子 每个格子有龙或者公主 勇士从1走到n 路过龙可以杀死可以不杀 杀死有钱拿 路过公主 如果之前杀龙的数量满足公主要求就会停止行走 问 勇士想多拿钱 但是必须要满足n格子的公主 最多拿多少钱
思路:
公主只限制杀龙的数量 因此不想停下来结婚就控制杀龙的数量即可 如果要放弃一些龙 那么一定会贪心放弃钱少的龙 最后判断一下能不能和n格子的公主结婚即可
代码:
#include<cstdio>#include<iostream>#include<cstring>#include<string>#include<algorithm>#include<map>#include<set>#include<vector>#include<queue>#include<cstdlib>#include<ctime>#include<cmath>using namespace std;#define N 200010int n;struct dragon {int x, id;bool operator<(const dragon ff) const {return x > ff.x;}} now;priority_queue<dragon> q;int ans[N], tot, sum;int main() {int i, k, s;char who[100];while (!q.empty())q.pop();scanf("%d", &n);for (i = 2; i <= n; i++) {scanf("%s%d", who, &k);if (i == n)break;if (who[0] == 'd') {now.x = k;now.id = i;q.push(now);} else {s = q.size();if (s >= k) {k = s - k + 1;while (k--)q.pop();}}}s = q.size();if (s < k)printf("-1\n");else {tot = sum = 0;while (!q.empty()) {now = q.top();q.pop();sum += now.x;ans[tot++] = now.id;}printf("%d\n", sum);printf("%d\n", tot);sort(ans, ans + tot);for (i = 0; i < tot; i++)printf("%d%s", ans[i], (i == tot - 1) ? "\n" : " ");}return 0;}
0 0
- sgu 548 Dragons and Princesses
- SGU 548 - Dragons and Princesses
- SGU 548 Dragons and Princesses
- [sgu 548] Dragons and Princesses
- SGU 548 Dragons and Princesses(贪心)
- Dragons and Princesses(优先队列)
- BNU - 26467 - Dragons and Princesses - 优先队列 + 想法
- Dragons
- Dragons
- SGU 548
- SGU 488 Dales and Hills
- SGU 495. Kids and Prizes
- Kids and Prizes - SGU 495
- SGU 495 Kids and Prizes
- SGU 495 Kids and Prizes
- A. Dragons
- Codeforces Dragons
- Dragons UVALive
- HDU--3829--Cat VS Dog【最大点独立集】
- linux c HTTP下载文件
- 动态规划 与两道例题
- 优先队列!
- 顺序表的实现
- SGU 548 Dragons and Princesses
- cp -R 和cp -r的区别
- 杭电2015
- windows客户端崩溃分析和调试
- using thymeleaf之三文字
- [Android]NetworkOnMainThreadException
- JSP脚本连接数据库的问题
- 用CFile判断文件末尾
- C#编程:多线程与UI操作