HDU 4415 Assassin’s Creed(贪心)
来源:互联网 发布:阿里云业务 编辑:程序博客网 时间:2024/05/18 16:18
实在难想,贪心。别人的思路:点击打开链接
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<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=1e5+10;struct node{ int w,s;}e[maxn];int visit[maxn];int t,n,s;int ans1,ans2,rs1,rs2;int cmp(node l1,node l2){ return l1.w<l2.w;}void solve_1(){ int i; rs1=s; ans1=0; for(int i=0;i<n;i++) { if(e[i].s) continue; if(rs1>=e[i].w) { ans1++; rs1-=e[i].w; } else break; }}void solve_2(){ int i; rs2=s; ans2=0; memset(visit,0,sizeof(visit)); for(i=0;i<n;i++) { if(e[i].s) break; }// cout<<"eeee "<<i<<endl; if(i>=n) return ; if(e[i].w>rs2) return ; int sum=0; for(int i=0;i<n;i++) sum+=e[i].s;// cout<<"222 "<<endl; if(sum+1>=n) {ans2=n;rs2-=e[i].w;return ;}// cout<<"11111 "<<endl; visit[i]=1; ans2=sum+1; rs2-=e[i].w; for(i=n-1;i>=0;i--) { if(!sum) break; if(!visit[i]) { visit[i]=1; sum--; } } for(i=0;i<n;i++) {// cout<<"fuck "<<endl; if(visit[i]) continue; if(rs2<e[i].w) break; ans2++; rs2-=e[i].w; }}int main(){ int cas=0; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&s); for(int i=0;i<n;i++) scanf("%d%d",&e[i].w,&e[i].s); sort(e,e+n,cmp); solve_1(); solve_2();// cout<<"fuck "<<ans1<<" "<<rs1<<" "<<ans2<<" "<<rs2<<endl; printf("Case %d: ",cas++); if(ans1>ans2||(ans1==ans2&&rs1>rs2)) printf("%d %d\n",ans1,s-rs1); else printf("%d %d\n",ans2,s-rs2); } return 0;}
0 0
- HDU 4415 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贪心)
- hdu-4415-Assassin’s Creed
- hdu 4415 Assassin’s Creed
- HDU 4415 Assassin’s Creed
- hdu 4415 Assassin’s Creed
- HDU 4415 Assassin’s Creed
- HDU 4415 Assassin’s Creed 苦逼的贪心
- hdu 4415 Assassin’s Creed 贪心 解题报告
- hdoj 4415 Assassin’s Creed 【贪心】
- Assassin’s Creed(hdu4415,贪心)
- 【贪心】 hdu4415 Assassin’s Creed
- hdu4415 Assassin’s Creed (贪心)
- hdu4415 Assassin’s Creed
- 【Hive】Hive笔记:Hive调优总结——数据倾斜,join表连接优化
- Android ViewPager使用详解
- zoj 2271 - Chance to Encounter a Girl
- spring batch : 在不同steps间传递数据
- C++细节笔记
- HDU 4415 Assassin’s Creed(贪心)
- 杭电acm2024C语言合法标识符
- LeetCode Word Search
- 'make menuconfig' requires the ncurses libraries.
- 常用编码软件简单使用记录 2 : 非自主编码器
- tomcat源码分析学习笔记(五)
- mysql 学习记录
- JAVA Socket超时浅析
- JAVA学习第十六课(内部类及其特点)