zoj3433(贪心+优先队列)
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
#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int n,t,m,b;
int main()
{
// freopen("C:/Users/lenovo/Desktop/input.txt","r",stdin);
// freopen("C:/Users/lenovo/Desktop/output.txt","w",stdout);
scanf("%d",&t);
while(t--)
{
vector<int>a[];
scanf("%d",&m);
for(int i=;i<m;i++)
{
scanf("%d",&n);
for(int j=;j<n;j++)
{
scanf("%d",&b);
a[i].push_back(b);
}
}
int sum=;
int k=;
int amp;
priority_queue<int>q;
for(int i=;i<m;i++)
{
scanf("%d",&);
//q.push(amp);
sum+=amp;
for(int j=;j<a[i].size();j++)
{
sum-=a[i][j];
k++;
q.push(a[i][j]);
}
while(sum<)
{
sum+=q.top();
q.pop();
k--;
} }
printf("%d\n",k);
}
return ;
}
zoj3433(贪心+优先队列)的更多相关文章
- hihoCoder 1309:任务分配 贪心 优先队列
#1309 : 任务分配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定 N 项任务的起至时间( S1, E1 ), ( S2, E2 ), ..., ( SN, ...
- UVA 11134 - Fabled Rooks(贪心+优先队列)
We would like to place n rooks, 1 ≤ n ≤ 5000, on a n×n board subject to the following restrict ...
- C. Playlist Educational Codeforces Round 62 (Rated for Div. 2) 贪心+优先队列
C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- HDU 6438 网络赛 Buy and Resell(贪心 + 优先队列)题解
思路:维护一个递增队列,如果当天的w比队首大,那么我们给收益增加 w - q.top(),这里的意思可以理解为w对总收益的贡献而不是真正获利的具体数额,这样我们就能求出最大收益.注意一下,如果w对收益 ...
- 贪心+优先队列 HDOJ 5360 Hiking
题目传送门 /* 题意:求邀请顺序使得去爬山的人最多,每个人有去的条件 贪心+优先队列:首先按照l和r从小到大排序,每一次将当前人数相同的被邀请者入队,那么只要能当前人数比最多人数条件小,该人能 被邀 ...
- [POJ1456]Supermarket(贪心 + 优先队列 || 并查集)
传送门 1.贪心 + 优先队列 按照时间排序从前往后 很简单不多说 ——代码 #include <queue> #include <cstdio> #include <i ...
- Painting The Fence(贪心+优先队列)
Painting The Fence(贪心+优先队列) 题目大意:给 m 种数字,一共 n 个,从前往后填,相同的数字最多 k 个在一起,输出构造方案,没有则输出"-1". 解题思 ...
- CF140C New Year Snowmen(贪心+优先队列)
CF140C 贪心+优先队列 贪心策略:每次取出数量最多的三种球,合成一个答案,再把雪球数都-1再插回去,只要还剩下三种雪球就可以不断地合成 雪球数用优先队列维护 #include <bits/ ...
- BZOJ1029: [JSOI2007]建筑抢修[模拟 贪心 优先队列]
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 3785 Solved: 1747[Submit][Statu ...
随机推荐
- paip.提升性能--- mysql 建立索引 删除索引 很慢的解决.
paip.提升性能--- mysql 建立索引 删除索引 很慢的解决. 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blo ...
- windows任务栏消失
windows任务栏消失,快捷键打开任务管理器,新建任务explorer.exe
- JAX-WS 可运行项目
该项目是通过JAX-WS实现的WebService服务,其中包括了1.关于最简单的WebService服务的创建2.关于文件交互的WebService的创建 代码中包括了服务端代码和客户端代码(客户端 ...
- Codeforces 549F Yura and Developers
probelm 题意 给定一个序列和一个mod值,定义[l,r]合法当l到r的全部元素和减去当中的最大值的结果能够整除mod.问共同拥有多少区间合法. 思路 一開始想的分治. 对于一个[l,r]我们能 ...
- NSSCanner 提取 指定 字符串
/** * 从msg中提取指定的内容 * * @param msg 字符串集合 * * @return 从msg中提取指定的内容 */ -(NSString*)extractBodyFromMe ...
- fopen 參数具体解释
fopen fopen(打开文件) 相关函数 open,fclose 表头文件 #include<stdio.h> 定义函数 FILE * fopen(const char * path, ...
- EffectiveC#17--装箱和拆箱的最小化
1.如下这段代码会经历装箱和拆箱.例如25会先装箱成object后传递给writeline方法(一次拷贝),在方法内部又 经历拆箱成int(第二次拷贝)后然后调用tostring(). Console ...
- jquery返回顶部
// 返回顶部 var fixed_totop = $('.back_top').on('click',function(){ $('html, body').animate({scrollTop: ...
- .net程序员转战android第三篇---登录模块之静态登录
这一篇我将分2个部分记录登录界面,第一部分是静态登录, 这部分将如何从界面布局.控件使用.文件关系.数据验证.登陆实现等5小块记录. 第二部分是动态登录,这块会基于上面的4小块,在数据验证不是静态数据 ...
- oracle 经典语句集合
1.一列转多行 方法一: select a.id, substr(','||a.name||',',instr(','||a.name,',',1,b.rn)+1, instr(a.name| ...