意甲冠军:

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 200010 int 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;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

SGU 548 Dragons and Princesses的更多相关文章

  1. codeforce447 D SGU 548 贪心+优先队列

    codeforce447 D - DZY Loves Modification 题意:有一个n*m的矩阵,每次可以选择一行或者一列,可以得到这行或这列的所有元素sum的积分,然后使这一列/行的每一个元 ...

  2. sgu548 Dragons and Princesses   贪心+优先队列

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=548 题目意思: 有一个骑士,要经过n个房间,开始在第一个房间,每个房间里面有龙或者 ...

  3. 2013/7/17 HNU_训练赛5

    sgu 542 Gena vs Petya sgu 543 Cafe 题意:有N组人需要被分配到某些固定了人数的桌子上,其中ai表示第i组有多少个人,安排作为需要符合如下安排:某一组的人员不能够单独在 ...

  4. SGU题目总结

    SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...

  5. NEERC Southern Subregional 2012

    NEERC Southern Subregional 2012 Problem B. Chess Championship 题目描述:有两个序列\(a, b\),两个序列都有\(n\)个数,并且这\( ...

  6. B. No Time for Dragons(贪心)

    B. No Time for Dragons time limit per test 2.0 s memory limit per test 256 MB input standard input o ...

  7. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  8. ACM: SGU 101 Domino- 欧拉回路-并查集

    sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Desc ...

  9. 【SGU】495. Kids and Prizes

    http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...

随机推荐

  1. 6月27日CTO俱乐部下午茶印象

    作者:朱金灿 来源:http://blog.csdn.net/clever101 感谢CSDN的邀请,有幸参加了6月27日“CTO俱乐部下午茶时光:CTO在团队管理中所遇到的那些事”活动.本期的主讲嘉 ...

  2. c++程序代写(qq:928900200)

     1. Both main memory and secondary storage are types of memory. Describe the difference between the  ...

  3. iOS 获取联系人,并调用系统地址簿UI

    1.加入 AddressBook库 推断授权状态 -(bool)checkAddressBookAuthorizationStatus { //取得授权状态 ABAuthorizationStatus ...

  4. VMware vSphere 服务器虚拟化之十六 桌面虚拟化之VMware Horizon View

       VMware vSphere服务器虚拟化之十六 桌面虚拟化之VMware Horizon View  VMware Horizon View (原VMware View的升级版现在版本5.2)是 ...

  5. Android应用性能測试

    Android内存限制 java虚拟机有内存使用上限的限制 adb shell进入手机,这此參数被纪录在/system/build.prop中,假设想直接查看能够使用adb shell getprop ...

  6. defgen工具

    构造defgen档 由于 Oracle 和 SQL Server 中的数据类型不同.所以您必须建立数据类型转换.GoldenGate 提供了一个名为 DEFGEN 的专用工具.用于生成数据定义,当源表 ...

  7. uml 9图不同的角度品种分类

    只要阅读uml视频后为其9一些模糊样图或理解.话又说回来后来他们自己的系统看着笔记,统的了解.以下分别从两个不同的角度对uml中9种图进行理解以及当中某些图的区分,本人比較菜,有些不完好的地方欢迎提出 ...

  8. hdu 1150 Machine Schedule(最小顶点覆盖)

    pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  9. php+sqlite 最佳web服务器

    1 wampserver   支持mysql.每次都启动mysql,可以手动停止.但是运行时有时会很慢. 放弃 2 APS绿色版(Apache+PHP+SQLite)  组件环境:Apache2.2. ...

  10. Codeforces 437E The Child and Polygon(间隔DP)

    题目链接:Codeforces 437E The Child and Polygon 题目大意:给出一个多边形,问说有多少种切割方法.将多边形切割为多个三角形. 解题思路:首先要理解向量叉积的性质,一 ...