博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1827 A Bunch Of Monsters 贪心
阅读量:6657 次
发布时间:2019-06-25

本文共 3924 字,大约阅读时间需要 13 分钟。

A Bunch Of Monsters
Time Limit: 2000MS   Memory Limit: 30000K
Total Submissions: 944   Accepted: 357

Description

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. 

Input

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.

Output

For each test case, print your answer, the minimum DAMAGE, in one line without any redundant spaces.

Sample Input

1 1117 76 4 4 2 3 4 310 70 20 60 30 50 400 0

Sample Output

050

Source

按照怪兽的伤害从大到小排序进行贪心:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pragma comment (linker,"/STACK:102400000,102400000")#define maxn 1005#define MAXN 2005#define mod 1000000009#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6typedef long long ll;using namespace std;struct str{ int num,val;};str s[500010];int visit[500010];int cmp(const str a,const str b){ return a.val>b.val;}int main(){ int i,j,n,m; while (scanf("%d%d",&n,&m)&&n&&m) { memset(visit,0,sizeof(visit)); for (i=1;i<=n;i++) scanf("%d",&s[i].num); for (i=1;i<=n;i++) scanf("%d",&s[i].val); sort(s+1,s+n+1,cmp); int sum=0; for (i=1;i<=n;i++) { for (j=s[i].num;j>0;j--) { if (!visit[j]) { visit[j]=1; break; } } if (j==0) sum+=s[i].val; } printf("%d\n",sum); } return 0;}

转载于:https://www.cnblogs.com/i8888/p/4044029.html

你可能感兴趣的文章
防止注入网上查了下用SqlParameter可以,那SqlParameter处理单引号时候是自动转义了吗...
查看>>
网页字体设置你了解吗?
查看>>
[Z] 计算机类会议期刊根据引用数排名
查看>>
通用权限管理设计 之 数据库结构设计
查看>>
外部中断实验
查看>>
从 datetime2 数据类型到 datetime 数据类型的转换产生一个超出范围的值
查看>>
HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)
查看>>
Sensor types
查看>>
CodeForces 35D Animals
查看>>
Atitit.工作流 与 规则引擎
查看>>
文字排版--斜体(font-style)
查看>>
使用ImageView
查看>>
sn 密钥注册
查看>>
IntelliJ IDEA安装、配置、测试
查看>>
[React] Using the classnames library for conditional CSS
查看>>
JStorm环境搭建
查看>>
代码保存好
查看>>
iOS: 字体样式
查看>>
hadoop程序MapReduce之MaxTemperature
查看>>
面试题16:反转链表
查看>>