zoukankan      html  css  js  c++  java
  • Hero

    Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    Description

    When playing DotA with god-like rivals and pig-like team members, you have to face an embarrassing situation: All your teammates are killed, and you have to fight 1vN. 

    There are two key attributes for the heroes in the game, health point (HP) and damage per shot (DPS). Your hero has almost infinite HP, but only 1 DPS. 

    To simplify the problem, we assume the game is turn-based, but not real-time. In each round, you can choose one enemy hero to attack, and his HP will decrease by 1. While at the same time, all the lived enemy heroes will attack you, and your HP will decrease by the sum of their DPS. If one hero's HP fall equal to (or below) zero, he will die after this round, and cannot attack you in the following rounds. 

    Although your hero is undefeated, you want to choose best strategy to kill all the enemy heroes with minimum HP loss.
     

    Input

    The first line of each test case contains the number of enemy heroes N (1 <= N <= 20). Then N lines followed, each contains two integers DPSi and HPi, which are the DPS and HP for each hero. (1 <= DPSi, HPi <= 1000)
     

    Output

    Output one line for each test, indicates the minimum HP loss.
     

    Sample Input

    1 10 2 2 100 1 1 100
     

    Sample Output

    20 201
     
     
    //又是贪心算法,题目就是要你一个人打N个人,然后输出最后你受到的伤害,最划算的方法不是先打攻击力高的,也不是血量少的,而是攻击力与血量比值最高的。嘛,也就是传说中中的性价比啦~
    那就按性价比从高到低排序吧~
    注意的地方是你在攻击他人的时,其余人也会对你造成伤害哦!也就是说在你打败一个人之前,你受到的伤害都是所有人的总攻击力啦,直到你把一个人打败才能改变,也就是说从开始,到打败一个人所受伤害即是被击败者的血量乘以初始所有人的总攻击力,然后减去被打败者的攻击力,继续循环下去....
    代码如下:
    #include <iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    
    struct Enemy
    {
        int hp;
        int dps;
    }enemy[25];
    
    bool cmp(const Enemy &a,const Enemy &b)
    {
        return (double)a.dps/(double)a.hp>(double)b.dps/(double)b.hp;
    }
    
    int main()
    {   int n;
        while(~scanf("%d",&n))
        {   int myhp=0;
            int alldps=0;
            memset(enemy,0,sizeof(enemy));
            for (int i=0;i<n;i++)
            {
                scanf("%d %d",&enemy[i].dps,&enemy[i].hp);
                alldps+=enemy[i].dps;
            }
                sort(enemy,enemy+n,cmp);
            for(int i=0;i<n;i++)
            {
                myhp+=enemy[i].hp*alldps;
                alldps-=enemy[i].dps;
            }
            printf("%d
    ",myhp);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    tensorflow初次接触记录,我用python写的tensorflow第一个模型
    java编写service详细笔记
    python聚类算法实战详细笔记 (python3.6+(win10、Linux))
    python kmeans实战
    C语言-apache mod(模块开发)-采用apxs开发实战(centos7.2 linux篇)
    C语言-apache mod(模块开发)-采用VS2017开发实战(windows篇)
    redis集群配置及运行命令(windows和centos)附Python测试范例代码
    centos 7 keepalived故障邮件通知实战(附Python邮件发送脚本)
    mysql互为主从实战设置详解及自动化备份(Centos7.2)
    keepalived安装配置实战心得(实现高可用保证网络服务不间断)
  • 原文地址:https://www.cnblogs.com/gdvxfgv/p/5689447.html
Copyright © 2011-2022 走看看