Problem Description
Ezio Auditore is a great master as an assassin. Now he has prowled in the enemies’ base successfully. He finds that the only weapon he can use is his cuff sword and the sword has durability m. There are n enemies he wants to kill and killing each enemy needs Ai durability. Every time Ezio kills an enemy he can use the enemy’s sword to kill any other Bi enemies without wasting his cuff sword’s durability. Then the enemy’s sword will break. As a master, Ezio always want to do things perfectly. He decides to kill as many enemies as he can using the minimum durability cost. 
Input
The first line contains an integer T, the number of test cases.
For each test case:
The first line contains two integers, above mentioned n and m (1<=n<=10^5, 1<=m<=10^9).
Next n lines, each line contains two integers Ai, Bi. (0<=Ai<=10^9, 0<=Bi<=10).
 

Output

For each case, output "Case X: " (X is the case number starting from 1) followed by the number of the enemies Ezio can kill and the minimum durability cost.
Sample Input
2
3 5
4 1
5 1
7 7
2 1
2 2
4 0
 
Sample Output
Case 1: 3 4 Case 2: 0 0
 
大致题意:
  用m点耐久度去杀人,杀死一个人需要Ai耐久度,但是获得的武器可以额外再杀死Bi个人。

  题目要求的首先是杀人最多,其次是消耗耐久度最少。

解题思路:

  贪心;

  如果能杀有剑的:

    先杀一个有剑的,有剑都能被杀死了;

    拿到所有剑后,剑的数量是固定的,那么用剑杀死的人数也是固定的,杀谁都一样;

    既然用剑杀谁都一样,那么不用剑就杀耗耐久最小的;

    所以按耗耐久由小到大排序,一个个杀过去到杀不动为止。

    如果这里面有有剑的怎么办呢? 没什么关系,他自己被耗耐久杀死了,那原本杀他的剑可以杀别人,用剑杀的人数都固定了;

    如果这么面没有有剑的怎么办呢?先杀有剑的耗耐久最小的咯;

  如果不能杀有剑的:

    还是按耐久由小到大排序,一个个杀过去到杀不动为止。

  综上:

    如果能杀有剑,那把有剑的耗耐久最小的杀掉,答案要加上剑的数量

    如果有剑的都不能杀,就不杀咯:

    剩余耐久肯定是依次杀耗耐久最小的,注意第一个杀的有剑的可能里面,那就要跳过;

  

 #include <cstdio>
#include <algorithm>
using namespace std;
#define N 100010
struct enemy{int a,b;}t[N];
bool cmp(enemy x,enemy y){ return x.a<y.a;}
int main(){
int T,n,m,cas=;
scanf("%d",&T);
while(T--){
int i,cost=,num=,k=-;
scanf("%d%d",&n,&m);
for(i=;i<n;i++) scanf("%d%d",&t[i].a,&t[i].b);
sort(t,t+n,cmp);
for(i=;i<n;i++)if(t[i].b) break;//找cost_min,b!=0的人
if(t[i].a<=m){
cost+=t[k=i].a;
for(num++,i=;i<n;i++) num+=t[i].b;//死一个有剑,有剑的全死 ,剑全拿上,剑杀人数固定了
} if(num>=n){printf("Case %d: %d %d\n",cas++,n,cost); continue;}
for(i=;i<n&&t[i].a+cost<=m&&num!=n;i++)if(i!=k)cost+=t[i].a,num++;
printf("Case %d: %d %d\n",cas++,num,cost);
}return ;
}

HDU 4415 - Assassin’s Creed的更多相关文章

  1. HDU 4415 Assassin&#39;s Creed(贪心)

    pid=4415">HDU 4415 题意: 壮哉我Assassin! E叔有一柄耐久度为m的袖剑,以及n个目标士兵要去解决. 每解决掉一个士兵,消耗袖剑Ai的耐久度.且获得该士兵的武 ...

  2. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  3. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  4. Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖

    题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...

  5. HDU-4415 Assassin’s Creed 贪心

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4415 用贪心来解,开始分为两个集合的方法错了,没有考虑之间的相互影响,正确的姿势应该是这样的,分两种情 ...

  6. ACM学习历程—HDU4415 Assassin’s Creed(贪心)

    Problem Description Ezio Auditore is a great master as an assassin. Now he has prowled in the enemie ...

  7. HDU4415 Assassin’s Creed

    题目大意:有n个人,每个人有x,y两个值.x代表干掉他得到的分数,分数和不超过m;y代表干掉他后你能额外干掉多少个,且不计入总分. 求干掉人数最多为多少,以及最小的分. ~~~~~~~~~~~~~~~ ...

  8. [GodLove]Wine93 Tarining Round #7

    比赛链接: http://vjudge.net/contest/view.action?cid=47643#overview 比赛来源: 2012 ACM/ICPC Asia Regional Han ...

  9. 微软Nokia 222:可拍照可上网 售价37美元 32GB的microSD卡扩展

    腾讯科技讯 8月27日,在几乎所有厂商都在智能手机领域大肆拼杀的时候,微软日前却悄悄地发布了一款功能手机Nokia 222. 目前,尽管全球许多发达国家的居民都对互联网已经再熟悉不过了,但事实上全球依 ...

随机推荐

  1. quick-x 2.2.5 DragonBones 某些fla导出使用后player卡死

    1 2 3 4 5 6 7 8 9 10 11     --test 龙骨   self._db = dragonbones.new({             skeleton="game ...

  2. NULL & nil & Nil & NSNULL的区别

    nil 是 OC 的,空对象,地址指向 空(0) 的对象 在 OC 中,可以给空对象发送任何消息,不会出现错误 NULL 是 C 的,空地址,地址的数值是 0,是一个长整数 表示地址是空 NSNull ...

  3. c#之process类相关整理

    一.根据进程名获取进程的用户名?   需要添加对 System.Management.dll 的引用   using System.Diagnostics; using System.Manageme ...

  4. twisted 使用

    工欲善其事,必先利其器,我们先来进行 twisted 框架的安装,由于平时使用的都是 Windows 系统,那么下面我们就讲解下 Windows 下 twisted 框架的安装(1)下载 twiste ...

  5. Ubuntu系统下创建python数据挖掘虚拟环境

    虚拟环境:   虚拟环境是用于创建独立的python环境,允许我们使用不同的python模块和版本,而不混淆.   让我们了解一下产品研发过程中虚拟环境的必要性,在python项目中,显然经常要使用不 ...

  6. Ubuntu 14.04卸载安装失败的Mysql数据库,以及重新安装配置

    一.删除原来Mysql 1.删除mysql的数据文件 sudo rm /var/lib/mysql/ -R 2.删除mqsql的配置文件 sudo rm /etc/mysql/ -R 3.自动卸载my ...

  7. Piggy-Bank (hdoj1114)

    Piggy-Bank Problem Description Before ACM can do anything, a budget must be prepared and the necessa ...

  8. Sql Server专题一:索引(上)

    写在前面的废话:索引问题已经是老生常谈的问题,虽然被经常说起,但作为我来说,至今没有用过索引(很可怕吧),我作为MS-BI实施工程师居然没用过索引,说话自然没底气.之前对索引的了解停留在“知道”的地步 ...

  9. js 获取浏览器内核

    <script language="JavaScript" type="text/javascript">    var browser = {   ...

  10. Esper

    https://www.igvita.com/2011/05/27/streamsql-event-processing-with-esper/ http://torycatkin.iteye.com ...