poj1827A Bunch Of Monsters(贪心)

题目链接:

啊哈哈,点我点我

题目意思:

给出n个怪物可以拿到卡片的范围和这个怪物对主人公造成的伤害。。然后求最后得到怪物对主人公的最小伤害。。

思路:对怪物造成的伤害从大到小排序,然后对n个怪物进行逐一枚举,枚举时对它的时间进行逆向枚举,然后没有被访问到的将其伤害降为0,最后统计一下即可。

题目:

A Bunch Of Monsters

Time Limit: 2000MS   Memory Limit: 30000K
Total Submissions: 938   Accepted: 354

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 1
1
1
7 7
6 4 4 2 3 4 3
10 70 20 60 30 50 40
0 0

Sample Output

0
50

Source

Atlas of [email protected]

代码为:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=50000+10;
int vis[maxn];

struct Damage
{
    int time,val;
}damage[maxn];

bool cmp(Damage a,Damage b)
{
    if(a.val==b.val)
        return a.time>b.time;
    else
        return a.val>b.val;
}

int main()
{
    int n,m;
    __int64 ans;
    while(~scanf("%d%d",&n,&m))
    {
        if(n==0&&m==0)  return 0;
        ans=0;
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=n;i++)
            scanf("%d",&damage[i].time);
        for(int i=1;i<=n;i++)
            scanf("%d",&damage[i].val);
        sort(damage+1,damage+1+n,cmp);
        for(int i=1;i<=n;i++)
        {
            int temp=damage[i].time;
            for(int j=temp;j>=1;j--)
            {
                if(!vis[j])
                {
                    damage[i].val=0;
                    vis[j]=1;
                    break;
                }
            }
        }
        for(int i=1;i<=n;i++)
            ans=ans+damage[i].val;
        printf("%I64d\n",ans);
    }
    return 0;
}

poj1827A Bunch Of Monsters(贪心),布布扣,bubuko.com

时间: 2024-12-10 17:01:47

poj1827A Bunch Of Monsters(贪心)的相关文章

poj 1827 A Bunch Of Monsters 贪心(并查集优化)

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 cont

Codeforces - 102222H - Fight Against Monsters - 贪心

https://codeforc.es/gym/102222/problem/H 题意:有一堆怪兽,怪兽有HP和ATK.你有一个英雄,英雄每次先被所有怪兽打,然后打其中一个怪兽.打的伤害递增,第一次1,第二次2,以此类推. 为什么感觉是贪心呢?证明一波. 首先开始打一个怪兽肯定一直打到死为止.那么打死他要求的次数可以二分出来(其实暴力也可以).两只怪兽交换打的顺序会不会变好? 先打第一只怪兽: \(num_1*sumatk+num_2*(sumatk-atk_1)\) 先打第二只怪兽: \(nu

2018 ACM-ICPC 宁夏 H.Fight Against Monsters(贪心)

It is my great honour to introduce myself to you here. My name is Aloysius Benjy Cobweb Dartagnan Egbert Felix Gaspar Humbert Ignatius Jayden Kasper Leroy Maximilian. As a storyteller, today I decide to tell you and others a story about the hero Huri

Codeforces #617 (Div. 3) D. Fight with Monsters(贪心,排序)

There are nn monsters standing in a row numbered from 11 to nn . The ii -th monster has hihi health points (hp). You have your attack power equal to aa hp and your opponent has his attack power equal to bb hp. You and your opponent are fighting these

Codeforces 1334C - Circle of Monsters(差值取前缀和 / 贪心)

两种思路其实只差在写法上 看不懂的就直接看代码吧qwq 题面 题意 n只怪物围成一圈,每只怪物拥有体力a和爆炸伤害b 如果怪物 i 死亡(体力小于等于0),则与他相邻的下一只怪物将受到 b[i] 点伤害 (如果 i<n ,则下一只怪物为 i+1 :如果 i==n,则下一只怪物为 1) 如果相邻的下一只怪物不存在,则什么也不会发生 如果相邻的下一只怪物受到伤害后也死亡了,那么再下一只怪物会继续受到伤害(链式反应) 每次你能随便挑一只怪物开一枪,那只怪物的体力将会降低 1 点 问至少需要开多少枪才能

多校第九场:贪心+矩阵快速幂中间优化+线性递推&amp;线段树递推

HDU 4968 Improving the GPA 思路:贪心的搞吧!比赛的时候想了好久,然后才发现了点规律,然后乱搞1A. 因为贪心嘛!大的情况就是刚开始每个人的分数都是最大的最小值,即绩点4.0的最低分数85,然后最后一个数设为剩余的分数,然后如果小于60就从第一个分数补到这个分数来,然后最后一个分数还小于60,那就用第二个补--依次往下搞,那时我也不知道这样就搞出答案了,我还没证明这个对不对呢,哈哈. 小的情况:小的情况就是先假设每个人都是绩点最小的最大分数,即绩点2.0的最大分数69,

【uva 1615】Highway(算法效率--贪心 区间选点问题)

题意:给定平面上N个点和一个值D,要求在x轴上选出尽量少的点,使得对于给定的每个店,都有一个选出的点离它的欧几里德距离不超过D. 解法:先把问题转换成模型,把对平面的点满足条件的点在x轴的直线上可得到一个个区间,这样就是选最小的点覆盖所有的区间的问题了.我之前的一篇博文有较详细的解释:关于贪心算法的经典问题(算法效率 or 动态规划).代码实现我先空着.挖坑~

【贪心+Treap】BZOJ1691-[Usaco2007 Dec]挑剔的美食家

[题目大意] 有n头奶牛m种牧草,每种牧草有它的价格和鲜嫩度.每头奶牛要求它的牧草的鲜嫩度要不低于一个值,价格也不低于一个值.每种牧草只会被一头牛选择.问最少要多少钱? [思路] 显然的贪心,把奶牛和牧草都按照鲜嫩度由大到小排序,对于每奶牛把鲜嫩度大于它的都扔进treap,然后找出后继. 不过注意后继的概念是大于它且最小的,然而我们这里是可以等于的,所以应该是找cow[i].fresh-1的后继,注意一下…… 1 #include<iostream> 2 #include<cstdio&

POJ1017 Packets(贪心算法训练)

Time Limit: 1000MS          Memory Limit: 10000K          Total Submissions: 51306          Accepted: 17391 Description A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These pro