zoj-3433-Gu Jian Qi Tan
/*
Gu Jian Qi Tan -------------------------------------------------------------------------------- Time Limit: 2 Seconds Memory Limit: 65536 KB -------------------------------------------------------------------------------- Gu Jian Qi Tan is a very hot Chinese RPG in this summer vacation. SuSu is the most important role in the game. When SuSu first meet the ancient dragon QianYu, he will have a very difficult battle with QianYu. In order to resist QianYu's powerful attack, SuSu must make a special armor, which needs some precious materials ( We call it "Ice Heart" ). Before this legend fight, SuSu must pass M dangerous labyrinth in order. In each labyrinth, there is a very powerful monster (We usually call it "BOSS") keeping watching the exit. So SuSu must defeat each BOSS if he wants to leave each labyrinth. When SuSu is fighting with a BOSS, he must attack its main body to kill it. however, some BOSS may have one or more special position of its body (such as wings, hands, weapons). SuSu can choose to attack these special positions and he will get one Ice Heart if he break the defence of one special position. Of course SuSu can choose not to attack special positions but just attack the BOSS's main body (in this situation, he can still kill the BOSS, but he cannot get Ice Heart). The defence of all special positions are so strong that normal attack are not available. SuSu must use magic skill to attack it. Once he uses a magic skill, his mana point will decrease to 0. In order to recover mana point, he can eat a special food "Dan Gui Hua Gao" (a kind of cake). In each labyrinth, SuSu can collect some cakes by killing small monsters. When he fights with a BOSS, his initial mana point will be 0. Different BOSS may have different amount of special positions, and the defence of different position may also be different ( that is, some positions may need just one magic attack but some may need to be attacked many times )
Notice: cakes in previous labyrinth can be accumulated and brought to later labyrinth. Can you tell how many Ice heart can SuSu get at most? Input
The first line of the input is a single integer T (T <= 20) indicating the number of test cases.
In each case, fisrt there is a line containing one integer M ( M <= 1000) indicating the number of labyrinth.
Then M lines follow. In the ith line, first there is an integer n (n <= 1000) indicating the amount of special positions this BOSS has.
Then followd by n integers, the ith integer ( no more than 20 ) indicating the amount of magic attacks SuSu must use to break the ith special position.
Finally there is a line containing M integers, the ith integer ( no more than 20 ) indicating how many cakes SuSu can collect in the ith labyrinth. Output
For each case, output one line, containing the maximum number of Ice Heart SuSu can get. Sample Input
1
2
1 10
2 1 2
10 0 Sample Output
2 --------------------------------------------------------------------------------
Author: HUANG, Qiao
Contest: ZOJ Monthly, November 2010 Submit Status
题意:有m层迷宫,每层迷宫有一只怪物,怪物有ni个“特别的位置”,
攻打每个位置需要cost[i]点魔,打完后可获得一个ice heart,
到达每层你就会有相应数量的魔,
每层的魔可以累加使用,让你求出最多获得几个ice heart。 解法:,尽可能地占下所有的ice heart,
如果占下某个ice heart时将当前积累的Cake消耗成了负数,
则放弃之前取得的一个消耗Cake最大的ice heart。 贪心。对于一个ice heart,如果当前cake数大于或等于该ice heart的消耗,
则直接取得,如果不,则用前面消耗的最大cake的与当前ice heart比较,
当前ice heart消耗小些,则交换,赚一点cake,否则不换。用一个最大堆维护即可。 */
#include <iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define maxn 2600 int main()
{
int T,t,M,n,i,j,sum,k;
scanf("%d",&T);
while(T--)
{
vector<int>a[maxn];
//开始把它定义成全局变量,没想到没有清空,报错
//放在这里时每次循环会从新定义,可以不清空
priority_queue<int> q;
scanf("%d",&M);
for(i=; i<M; i++)
{
scanf("%d",&n);
for(j=; j<n; j++)
{
scanf("%d",&t);
a[i].push_back(t);
} }
sum=;
k=;
for(i=; i<M; i++)
{
scanf("%d",&t);
sum+=t;
for(j=; j<a[i].size(); j++)
{
sum-=a[i][j];
q.push(a[i][j]);
k++; }
while(sum<)
{
sum+=q.top();
q.pop();
k--;
} }
/* for(i=0;i<M;i++)
{
for(j=0;j<a[i].size();j++)
cout<<a[i][j]<<" ";
cout<<endl;
}*/
while(!q.empty())q.pop();
printf("%d\n",k);
}
return ;
}
zoj-3433-Gu Jian Qi Tan的更多相关文章
- zoj3433(贪心+优先队列)
Gu Jian Qi Tan Time Limit: 2 Seconds Memory Limit: 65536 KB Gu Jian Qi Tan is a very hot Chines ...
- php获取汉字的拼音 拼音首字母
/***获取汉字的拼音*/function pinyin($s, $isfirst = false) { static $pinyins; $s = trim($s); $len = strlen($ ...
- [C#] 汉字转拼音,支持多音字
这份代码大概不是严格意义上正确的,但是一般场景用用应该没问题. using System; using System.Collections.Generic; using System.Linq; u ...
- [Erlang20]一起攻克Binary
第一次看到Joe Armstong的<Erlang 程序设计>里面对Binary的描述时,觉得这个东西好复杂,语法这么奇特(我觉得是Erlang语法中最不好懂的部分); 然后在项目中:Bi ...
- ZOJ 3794 Greedy Driver
两次SPFA 第一关找:从1没有出发点到另一个点的多少是留给油箱 把边反过来再找一遍:重每一个点到终点最少须要多少油 Greedy Driver Time Limit: 2 Seconds ...
- ZOJ 3635 Cinema in Akiba[ 大规模阵列 ]
门户:problemCode=3635">ZOJ 3635 Cinema in Akiba Time Limit: 3 Seconds Memory Limit: 65536 ...
- ZOJ 3228 Searching the String(AC自动机)
Searching the String Time Limit: 7 Seconds Memory Limit: 129872 KB Little jay really hates to d ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
随机推荐
- Linux下使用Opencv打开笔记本摄像头
新建test文件夹,文件夹存在test.cpp和CMakeLists.txt test.cpp#include <iostream> #include <string> #in ...
- 深入理解Feign之源码解析
转载请标明出处: 本文出自方志朋的博客 什么是Feign Feign是受到Retrofit,JAXRS-2.0和WebSocket的影响,它是一个jav的到http客户端绑定的开源项目. Feign的 ...
- [置顶]
Isolation Forest算法实现详解
本文算法完整实现源码已开源至本人的GitHub(如果对你有帮助,请给一个 star ),参看其中的 iforest 包下的 IForest 和 ITree 两个类: https://github.co ...
- Mac 配置前端基本环境
一,sublime 下载一个版本,替换packages,要想shift command p管用,得在sublime里面control -,然后把 import urllib.request,os,h ...
- Git详解之九 Git内部原理
以下内容转载自:http://www.open-open.com/lib/view/open1328070620202.html Git 内部原理 不管你是从前面的章节直接跳到了本章,还是读完了其余各 ...
- python 生成器推导式与列表推导式的区别
生成器表达式现用现生成,列表推导式一次性生成静态数据 L = [2, 3, 5, 7] L2 = (x**2+1 for x in L) it = iter(L2) print(next(it)) L ...
- WPF 使用 WindowChrome,在自定义窗口标题栏的同时最大程度保留原生窗口样式(类似 UWP/Chrome)
WPF 自定义窗口样式有多种方式,不过基本核心实现都是在修改 Win32 窗口样式.然而,Windows 上的应用就应该有 Windows 应用的样子嘛,在保证自定义的同时也能与其他窗口样式保持一致当 ...
- 《DSP using MATLAB》示例Example 8.14
%% ------------------------------------------------------------------------ %% Output Info about thi ...
- Appium+python (3) 异常处理
有时候定位时会发现无法定位到具体的元素,右侧元素定位处只告诉你这是一个网页视图: 点击里面的具体元素是无法选中的,船长的做法是回到App里点一下元素,再返回要定位的页面,重新点一下Device Scr ...
- C#封装的一个JSON操作类
using System; using System.Collections.Generic; using System.Collections; using System.Text; using S ...