SGU 548 Dragons and Princesses
意甲冠军:
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的更多相关文章
- codeforce447 D SGU 548 贪心+优先队列
codeforce447 D - DZY Loves Modification 题意:有一个n*m的矩阵,每次可以选择一行或者一列,可以得到这行或这列的所有元素sum的积分,然后使这一列/行的每一个元 ...
- sgu548 Dragons and Princesses 贪心+优先队列
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=548 题目意思: 有一个骑士,要经过n个房间,开始在第一个房间,每个房间里面有龙或者 ...
- 2013/7/17 HNU_训练赛5
sgu 542 Gena vs Petya sgu 543 Cafe 题意:有N组人需要被分配到某些固定了人数的桌子上,其中ai表示第i组有多少个人,安排作为需要符合如下安排:某一组的人员不能够单独在 ...
- SGU题目总结
SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...
- NEERC Southern Subregional 2012
NEERC Southern Subregional 2012 Problem B. Chess Championship 题目描述:有两个序列\(a, b\),两个序列都有\(n\)个数,并且这\( ...
- 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 ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
- 【SGU】495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...
随机推荐
- Java EE (7) -- Java EE 6 Enterprise Architect Certified Master(1z0-807)
Application Design Concepts and Principles Identify the effects of an object-oriented approach to sy ...
- ACM:回溯,八皇后问题,素数环
(一)八皇后问题 (1)回溯 #include <iostream> #include <string> #define MAXN 100 using namespace st ...
- 王立平--Unity综上所述控制
GUILayout Label 创建一个自己主动布局的标签. Box 创建一个自己主动布局的box. Button 创建一个单次button.当用户点击button会马上发生一些事件. Repea ...
- ExternalInterface的简单使用方法
ExternalInterface的简单使用方法 使用ExternalInterface调用JavaScript方法-无返回值flex代码------------------<mx:Button ...
- Android AlarmManager报警的实现
什么是AlarmManager? AlarmManager它是Android经常使用的系统-Level提醒服务,我们指定为广播中的特定时间Intent. 我们设定一个时间,然后在该时间到来时.Alar ...
- statickeyword于C和C++用法
一.C语言statickeyword两个使用 1).一个功能修改内部使用的变量,函数内的静态变量.这些变量的寿命比功能不再,它是具有一定的函数"状态",使用静态变量的作用通常是不可 ...
- 光谱郑匡移动互联网O2O完美融合
移动互联网尽管市场颇大,前景广阔,可是由于数据过于密集,非常难精准的定位所谓的目标客户群,然而O2O的线下市场却与互联网市场有极大的反差.一直认为高校周边的小商家是最幸福的生意人,客户明白(就是本校学 ...
- Android动画之二:View Animation
作为一个博客<Android其中的动画:Drawable Animation>.android动画主要分为三大部分.上一篇博客已经解说Drawable Animation的使用方法,即逐帧 ...
- Scala---For语句段
For语句段 语法: Expr1 ::= „for‟ („(‟ Enumerators „)‟ | „{‟ Enumerators „}‟) {nl} [„yield‟] Expr Enumerato ...
- Guest与virtio netdev交互模式
Qemu为virtio设备分配了专门的pci设备ID,device IDs (vendor ID 0x1AF4) from 0x1000 through 0x10FF,而pci子系统中的厂商ID和设备 ...