LDU个人训练三 2018宁夏邀请赛 H Fight Against Monsters

Problem H.

Fight Against Monsters Time limit: 10 seconds 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 Huriyyah, and the monsters. Once upon a time, citizens in the city were suffering from n powerful monsters. They ate small children who went out alone and even killed innocent persons. Before the hero appeared, the apprehension had overwhelmed the people for several decades. For the good of these unfortunate citizens, Huriyyah set off to the forest which was the main lair of monsters and fought with n fierce and cruel monsters. The health point of the i-th monster was HPi , and its attack value was ATKi . They fought in a cave through a turn-based battle. During each second, the hero Huriyyah was attacked by monsters at first, and the damage was the sum of attack values of all alive monsters. Then he selected a monster and attacked it. The monster would suffer the damage of k (its health point would decrease by k) which was the times of attacks it had been came under. That is to say, for each monster, the damage of the first time that Huriyyah attacked it was 1, and the damage of Huriyyah’s second attack to this monster was 2, the third time to this monster was 3, and so on. If at some time, the health point of a monster was less than or equal to zero, it died. The hero won if all monsters were killed. Now, my smart audience, can you calculate the minimum amount of total damages our hero should suffer before he won the battle?

Input

The input contains several test cases, and the first line is a positive integer T indicating the number of test cases which is up to 103 . For each test case, the first line contains an integers n (1 ≤ n ≤ 105 ) which is the number of monsters. The i-th line of the following n lines contains two integers HPi and ATKi (1 ≤ HPi , ATKi ≤ 105 ) which describe a monster. We guarantee that the sum of n in all test cases is up to 106 . Output For each test case, output a line containing Case #x: y, where x is the test case number starting from 1, and y is the minimum amount of total damages the hero should suffer. Sample standard input standard

output

2 3

1 1

2 2

3 3

3

3 1

2 2

1 3

Case #1: 19

Case #2: 14

中文翻译: 现在有 n 只怪兽,每只怪兽有一个体力值 HPi 和一个攻击值 ATKi。 英雄需要同时和这 n 只怪兽进行战斗。 在每一秒,首先英雄会被当前未被打倒的所有怪兽攻击,受到与这些怪兽的攻击值之和等量的伤害。 然后他要选择一只未被打倒的怪兽进行攻击。对同一只怪物进行的第 i 次攻击能对其造成 i 点伤害。 当怪兽的体力值 ≤ 0 的时候就会倒下,当所有怪兽都被打倒时战斗立即结束。 英雄需要合理地进行攻击以使战斗过程中受到的伤害之和最小,请你求出这个伤害总量。

输入格式

第一行包含一个整数 T,表示有 T 组测试数据。 接下来依次描述 T 组测试数据。对于每组测试数据: 第一行包含一个整数 n,表示怪兽的数量。 接下来 n 行,每行包含两个整数 HPi , ATKi,表示每只怪兽的体力值和攻击值。

输出格式

对于每组测试数据,输出一行信息 "Case #x: y"(不含引号),其中 x 表示这是第 x 组测试数据, y 表示战斗过程中受到的伤害之和的最小值。

思路:因为在打击怪兽的过程中需要让自己受到的伤害值最小,所以说要找那些打的少而且攻击力高的怪兽,所以说在进行排序时的规矩则是打击次数少比上战斗值少的怪兽首先被打,刚开始想的是体力值比上战斗值,但是后来发现不行,因为体力值是2和3的在战斗值相同的情况下比值是不一样的,但是他们的被打击次数确是一样的,所以行不通。

#include 
using namespace std;
typedef long long ll;
int dir[4][2]={0,1,0,-1,-1,0,1,0};
struct node{
    ll hp,ak;
    ll time;
}pp[100010];
int judge(int x)
{
    int i=1;
    int cnt=0;
    while(1)
    {
        x-=i;
        i++;
        cnt++;
        if(x<=0)
            break;
    }
    return cnt;
}
bool cmp(node a,node b)
{
    return a.time*b.ak

 

你可能感兴趣的:(LDU个人训练)