POJ 1827 Bunch Of Monsters(贪心)
来源:互联网 发布:经济数据查询 编辑:程序博客网 时间:2024/06/06 02:01
Background
Jim is a brave explorer. One day, he set out for his next destination, a mysterious hill. When he arrived at the foot of the hill, he was told that there were a bunch of monsters living in that hill, and was dissuaded from continuing his trip by the residents near the hill. Nevertheless, our Jim was so brave that he would never think of giving up his exploration.
The monsters do exist! When he got into that hill, he was caught by a bunch of fearful monsters.
Fortunately, the monsters didn’t plan to kill him or eat him for they were planning a big party. They wanted to invite Jim, a clever human being, to their party, in order to let human beings know that the monsters also have wonderful parties.
Problem
At the end of the party, the monsters promised that, after the last game, they would set Jim free. The game is described as follow:
1. There are a great many boxes of treasure, which are numbered from 1 to X. One box has the only one number; one number can only appear on one box. Furthermore, we can assume that X is INFINITY, because the monsters have got a lot of treasure from the men they caught.
2. There are N monsters in this game. Each picks up a card randomly. After that, he / she (it?) opens it, getting a positive integer number d[i], and cannot change it or pick up another card again. The range of d[i] is from 1 to M. If the i-th monster get the number d[i], he can only get the treasure box numbered equal to or less than d[i]. What’s more, one box only can be distributed to one monster; one monster can only get one box.
3. Of course, there are many ways to distribute the boxes to the monsters when N monsters get their numbers; and not every monster can get a box in many cases. Jim has the right to make the arrangement; however, he also knows that the monsters that don’t get the boxes will also punish him.
Jim knows the strength of the N monsters. The i-th one has the strength s[i]. We call the sum of strength s[i] of all the monsters that don’t get the boxes --- the DAMAGE to Jim. Your task is to help Jim find out the minimum DAMAGE to him.
Jim is a brave explorer. One day, he set out for his next destination, a mysterious hill. When he arrived at the foot of the hill, he was told that there were a bunch of monsters living in that hill, and was dissuaded from continuing his trip by the residents near the hill. Nevertheless, our Jim was so brave that he would never think of giving up his exploration.
The monsters do exist! When he got into that hill, he was caught by a bunch of fearful monsters.
Fortunately, the monsters didn’t plan to kill him or eat him for they were planning a big party. They wanted to invite Jim, a clever human being, to their party, in order to let human beings know that the monsters also have wonderful parties.
Problem
At the end of the party, the monsters promised that, after the last game, they would set Jim free. The game is described as follow:
1. There are a great many boxes of treasure, which are numbered from 1 to X. One box has the only one number; one number can only appear on one box. Furthermore, we can assume that X is INFINITY, because the monsters have got a lot of treasure from the men they caught.
2. There are N monsters in this game. Each picks up a card randomly. After that, he / she (it?) opens it, getting a positive integer number d[i], and cannot change it or pick up another card again. The range of d[i] is from 1 to M. If the i-th monster get the number d[i], he can only get the treasure box numbered equal to or less than d[i]. What’s more, one box only can be distributed to one monster; one monster can only get one box.
3. Of course, there are many ways to distribute the boxes to the monsters when N monsters get their numbers; and not every monster can get a box in many cases. Jim has the right to make the arrangement; however, he also knows that the monsters that don’t get the boxes will also punish him.
Jim knows the strength of the N monsters. The i-th one has the strength s[i]. We call the sum of strength s[i] of all the monsters that don’t get the boxes --- the DAMAGE to Jim. Your task is to help Jim find out the minimum DAMAGE to him.
The input consists of several test cases. In the first line of each test case, there are two positive integers N and M (1<=N<=50000, 1<=M<=50000), indicating the number of monsters and the range of numbers the monsters possibly get on the cards. Then there are N integers d[i] (1<=d[i]<=M) in the following lines, which are the numbers those monsters got. And in the rest lines of one test case, there are other N positive integers s[i] (1<=s[i]<=20000), indicating the strength of each monsters. The test case starting with 2 zeros is the final test case and has no output.
For each test case, print your answer, the minimum DAMAGE, in one line without any redundant spaces.
1 1117 76 4 4 2 3 4 310 70 20 60 30 50 400 0
050
题解:
比较水的一道贪心,但题意较难理解,就是有n个怪,m个盒子标号1,2。。。m,n个怪有不同的伤害,他们要标号在a[i]之前或者相同的盒子才不会揍你,每个怪只拿一个盒子,一种号的盒子也只有一种,然后b[i]是每个怪的伤害,问你最后最少会被揍多少血
思路:将怪伤害从大到小排序,同等就所需大的在前,尽量给他们大号的盒子给后面腾盒子防被打,遍历一遍排好序的盒子,如果可以拿到就继续,不能就累加掉的血,然后数据有点大最好用long long,用int也可以好像
代码:
#include<algorithm>#include<iostream>#include<cstring>#include<stdio.h>#include<math.h>#include<string>#include<stdio.h>#include<queue>#include<stack>#include<map>#include<deque>#define M (t[k].l+t[k].r)/2#define lson k*2#define rson k*2+1using namespace std;struct mon{ int need; int strength;}a[50005];int cmp(mon x,mon y){ if(x.strength!=y.strength) return x.strength>y.strength; return x.need>y.need;}int vis[50005];int main(){ int i,j,k,n,m,tag; long long s; while(scanf("%d%d",&n,&m)!=EOF) { if(n==0&&m==0) break; for(i=0;i<n;i++) { scanf("%d",&a[i].need); } for(i=0;i<n;i++) { scanf("%d",&a[i].strength); } memset(vis,0,sizeof(vis)); sort(a,a+n,cmp); s=0; for(i=0;i<n;i++) { tag=0; for(j=a[i].need;j>=1;j--) { if(!vis[j]) { tag=1; vis[j]=1; break; } } if(!tag) { s+=a[i].strength; } } printf("%lld\n",s); } return 0;}
阅读全文
0 0
- poj 1827 A Bunch Of Monsters 贪心
- POJ 1827 Bunch Of Monsters(贪心)
- POJ 1827 A Bunch Of Monsters(贪心)
- poj 1827 A Bunch Of Monsters
- poj 1827 A Bunch Of Monsters
- POJ 1827 A Bunch Of Monsters 题解
- poj1827A Bunch Of Monsters(贪心)
- poj 1827 A Bunch Of Monsters 贪心(并查集优化)
- Flashers: Just a bunch of copycats ??????
- JBOD (just a bunch of disks or just a bunch of drives)
- POJ 1775 Sum of Factorials DFS 贪心
- POJ 2109 Power of Cryptography 贪心
- A bunch of tech news related to China from Yahoo
- JBOD(Just a Bunch Of Disks,磁盘簇)简介
- Escape from Age of Monsters:让小朋友先逃吧,主角
- tHackerrank Fight the Monsters!Week of Code 32
- POj 3601 Tower of Hanoi 汉诺塔(贪心)
- UVa 11292 / POJ 3646 / HDU 1902 Dragon of Loowater (贪心)
- PCA降维操作及subplot子图绘制
- java ArrayList集合反转 学习笔记
- 枚举值与枚举类
- 《tensorflow实战》注释源码版
- java final关键字
- POJ 1827 Bunch Of Monsters(贪心)
- test
- 使用Jenkins进行持续集成
- USACO-Section2.1 The Castle
- ORACLE 某表执行SQL历史,Java 调用历史SQL
- hdu6069
- 支付宝SDK出现的问题---缺少签名参数 无效签名
- springMVC 对参数为null或参数不为null的处理
- PyCharm下载安装