hdu4415 Assassin’s Creed
来源:互联网 发布:中银淘宝校园卡办理 编辑:程序博客网 时间:2024/06/02 18:26
Assassin’s Creed
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1311 Accepted Submission(s): 337
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).
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
23 54 15 17 72 12 24 0
Sample Output
Case 1: 3 4Case 2: 0 0
Source
2012 ACM/ICPC Asia Regional Hangzhou Online
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#define MAXN 100050using namespace std;int a[MAXN],b[MAXN],c[MAXN];bool cmp(int a,int b){return a<b;}int main(){ int i,tcase,n,m,ans1,ans2,tempm,tempa,tempb,numc,numa,numb,sumb,t=1,m2; scanf("%d",&tcase); while(tcase--) { scanf("%d%d",&n,&m); tempm=m,ans1=ans2=0,m2=m; numa=numb=0;sumb=0; for(i=0;i<n;i++) { scanf("%d%d",&tempa,&tempb); if(tempb==0) { a[numa]=tempa;numa++; } else { b[numb]=tempa,numb++,sumb+=tempb; } } sumb-=numb-1; sort(a,a+numa,cmp); sort(b,b+numb,cmp); for(i=0;i<numa;i++) { if(m>=a[i]) m-=a[i],ans1++; else break; } m2=m; m=tempm; if(m>=b[0]&&numb>0) { m=m-b[0];ans2=numb+sumb; if(ans2<n) { numc=0; for(i=0;i<numa;i++) c[numc++]=a[i]; for(i=1;i<numb;i++) c[numc++]=b[i]; sort(c,c+numc,cmp); for(i=0;i<numc;i++) { if(m>=c[i]) { m-=c[i],ans2++; } if(ans2>=n) break; } } else ans2=n; } if(ans2>ans1) printf("Case %d: %d %d\n",t++,ans2,tempm-m); else if(ans2==ans1) printf("Case %d: %d %d\n",t++,ans1,min(tempm-m2,tempm-m)); else printf("Case %d: %d %d\n",t++,ans1,tempm-m2); } return 0;}
- hdu4415 Assassin’s Creed
- hdu4415 Assassin’s Creed
- hdu4415 Assassin's Creed
- hdu4415 Assassin’s Creed
- 【贪心】 hdu4415 Assassin’s Creed
- hdu4415 Assassin’s Creed (贪心)
- Assassin’s Creed(hdu4415,贪心)
- HDU4415 Assassin’s Creed 2012ACM/ICPC 杭州赛区网络赛 F
- F - Assassin’s Creed
- hdu-4415-Assassin’s Creed
- hdu 4415 Assassin’s Creed
- HDU 4415 Assassin’s Creed
- hdu 4415 Assassin’s Creed
- Assassin’s Creed(天津online)
- HDU 4415 Assassin’s Creed
- Assassin’s Creed贪心)
- Light1406 Assassin`s Creed【状压】
- hdu 4415 Assassin’s Creed 贪心
- 遮盖与投影
- wxWidgets UI笔记
- Android开源
- 当java swing界面启动无法正常显示,当调整JFrame大小后才能全部显示子组件
- 在ios中运用core animation暂停和继续动画
- hdu4415 Assassin’s Creed
- 赖勇浩:推荐《Linux 多线程服务器端编程》
- “啃老”族,蹭住多久才算久?
- hdu4414 Finding crosses
- [二次开发]dede会员列表调用(企业、个人)
- 9.3 折半查找
- clip:rect('top', 'right', 'bottom', 'left')
- Jackson多态类型数据的反序列化
- hdu4417 Super Mario