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. GET & POST 登录

    GET 登录 @property(nonatomic,assign)long  long hasReceivedContentLength; - (void)getLogin { NSString * ...

  2. arm ldr 指令

    ldr 指令格式:(读取概念) ldr{条件} 1目的寄存器,2存储器地址 eg: ldr r0,[r1]; 把r1中数据值读取到r0中: ldr r0,[r1,r2];把r1+r2的数值 读取到r0 ...

  3. apache 设置

    此博客是网站www.beilei123.cn镜像,转载请注明出处. 1.ServerTokens ProdServerTokens Prod 显示“Server: Apache”ServerToken ...

  4. java中如何调用oracle存储过程

    在java中使用CallableStatement调用存储过程 列: 创建需要的测试表:create table Test(tid varchar2(10),tname varchar2(10)): ...

  5. HTML5的结构学习(3) --- 综合运用

    前面学习了HTML5新增的主体结构元素和新增的非主体结构元素, 而这里我们来学习如何去综合的运用这些新增元素. 1.大纲 HMTL5元素的关键就是将显示内容和便签类型紧密相关,提高了代码的语义化和可读 ...

  6. Computer Transformation(hdoj 1041)

    Problem Description A sequence consisting of one digit, the number 1 is initially written into a com ...

  7. web安全测试工具介绍---webscarab

    webscarab: 这主要是一款代理软件或许没有其它的工具能和OWASP的WebScarab如此丰富的功能相媲美了,如果非要列举一些有用的模块的话,那么他们包括HTTP代理,网络爬行.网络蜘蛛,会话 ...

  8. Can't create a new thread (errno 11); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug

    解决方案: http://www.javatang.com/archives/2013/06/19/2701909.html

  9. 忽然有一种感觉:云存储必须从系统级定制,所以必须对Linux相当熟悉。Windows下开发软件的模式已经过时了

    看了诸多招聘帖子以后的感觉- 工作内容: .存储相关产品的设计.开发和维护. .Linux系统应用程序研发. .主流Linux内核文件系统研发. .自动化测试框架和工具的研发. 职位要求: .计算机相 ...

  10. Intuit Quicken Home & Business 2016(Manage your business and personal finances)

    Quicken Home & Business 2016 - Manage your business and personal finances all in one place. Cate ...