HDU 4415 - Assassin’s Creed

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 4415 - Assassin’s Creed相关的知识,希望对你有一定的参考价值。

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个人。

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

解题思路:

  贪心;

  如果能杀有剑的:

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

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

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

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

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

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

  如果不能杀有剑的:

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

  综上:

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

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

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

  

 1 #include <cstdio>
 2 #include <algorithm>
 3 using namespace std;
 4 #define N 100010
 5 struct enemy{int a,b;}t[N];
 6 bool cmp(enemy x,enemy y){ return x.a<y.a;}
 7 int main(){
 8     int T,n,m,cas=1;
 9     scanf("%d",&T);
10     while(T--){
11         int i,cost=0,num=0,k=-1;
12         scanf("%d%d",&n,&m);
13         for(i=0;i<n;i++) scanf("%d%d",&t[i].a,&t[i].b);
14         sort(t,t+n,cmp);
15         for(i=0;i<n;i++)if(t[i].b) break;//找cost_min,b!=0的人
16         if(t[i].a<=m){
17             cost+=t[k=i].a;
18             for(num++,i=0;i<n;i++) num+=t[i].b;//死一个有剑,有剑的全死 ,剑全拿上,剑杀人数固定了 
19         } if(num>=n){printf("Case %d: %d %d\n",cas++,n,cost); continue;}
20         for(i=0;i<n&&t[i].a+cost<=m&&num!=n;i++)if(i!=k)cost+=t[i].a,num++;
21         printf("Case %d: %d %d\n",cas++,num,cost);
22     }return 0;
23 }

 

以上是关于HDU 4415 - Assassin’s Creed的主要内容,如果未能解决你的问题,请参考以下文章

HDU4415 Assassin’s Creed

hdu 4738 Caocao's Bridges

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

[游戏分析]刺客信条:兄弟会(Assassin's Creed: Brotherhood)

第三次作业 史浩然 -assassin Talon

贪心10.24assassin