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 10^3 .

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 10^6 .

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.

样例输入


样例输出

Case #: 

Case #: 

题意:
有 n 个怪物 , 每个怪物都有v的生命值 和 w 的攻击值,现在有个英雄要为民除害 ,杀掉这些怪物。

英雄对每个怪物的伤害值都是从1 开始依次加一(比如英雄第一次伤害A , 伤害值是1 , 第二次是2 ……, 然后伤害B 是1 ,再次伤害B 是2……)英雄每次会受到所有活着的怪物的攻击值总和。

问英雄受到的最小攻击值是多少?

 思路:

由怪物的生命值可以得到英雄杀死该怪物需要的次数 ,按照这个怪物的攻击值 / 怪物被杀的次数 从大到小排序贪心,计算总的伤害值即可

注意:

1. 记得开long long

2. 比值排序有精度误差 , 改成这样: a/b > c/d= a*d > b*c

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <math.h>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
const int maxn=1e5+;
using namespace std; struct E_node
{
int HP;
int ATK;
int num;
}E[maxn]; bool cmp(E_node a,E_node b)
{
return a.ATK*b.num>b.ATK*a.num;
} int main()
{
int T;
scanf("%d",&T);
for(int k=;k<=T;k++)
{
int n;
scanf("%d",&n);
LL all_ATK=;
for(int i=;i<=n;i++)
{
scanf("%d %d",&E[i].HP,&E[i].ATK);
all_ATK+=E[i].ATK;
int sum=;
int j;
for(j=;sum<E[i].HP;j++)
{
sum+=j;
}
E[i].num=j-;
}
sort(E+,E++n,cmp);
LL ans=;
for(int i=;i<=n;i++)
{
ans+=all_ATK*E[i].num;
all_ATK-=E[i].ATK;
}
printf("Case #%d: %lld\n",k,ans);
}
return ;
}

2018 ACM-ICPC 宁夏 H.Fight Against Monsters(贪心)的更多相关文章

  1. 2019 ICPC 银川网络赛 H. Fight Against Monsters

    It is my great honour to introduce myself to you here. My name is Aloysius Benjy Cobweb Dartagnan Eg ...

  2. 2018 ACM ICPC 南京赛区 酱油记

    Day 1: 早上6点起床打车去车站,似乎好久没有这么早起床过了,困到不行,在火车上睡啊睡就睡到了南京.南航离南京南站很近,地铁一站就到了,在学校里看到了体验坐直升机的活动,感觉很强.报道完之后去吃了 ...

  3. 2018 ACM/ICPC 南京 I题 Magic Potion

    题解:最大流板题:增加两个源点,一个汇点.第一个源点到第二个源点连边,权为K,然后第一个源点再连其他点(英雄点)边权各为1,然后英雄和怪物之间按照所给连边(边权为1). 每个怪物连终点,边权为1: 参 ...

  4. Codeforces - 102222H - Fight Against Monsters - 贪心

    https://codeforc.es/gym/102222/problem/H 题意:有一堆怪兽,怪兽有HP和ATK.你有一个英雄,英雄每次先被所有怪兽打,然后打其中一个怪兽.打的伤害递增,第一次1 ...

  5. HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  6. 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛

    比赛链接: http://202.197.224.59/OnlineJudge2/index.php/Contest/problems/contest_id/36 题目来源: 2014嘉杰信息杯ACM ...

  7. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time

    Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...

  8. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  9. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

随机推荐

  1. Linux文件和目录的属性及权限

    Linux文件和目录的属性及权限讲解 文字解释: 第一列:inode索引节点 第二列:文件类型及权限 第三列:硬链接个数 第四列:文件或目录所属的用户(属主) 第五列:文件或目录所属的用户所归属的组( ...

  2. 8.scrapy的第一个实例

    [目标]要完成的任务如下: ※ 创建一个 Scrap项目.※ 创建一个 Spider来抓取站点和处理数据.※ 通过命令行将抓取的内容导出.※ 将抓取的内容保存的到 MongoDB数据库.======= ...

  3. git使用散记

    1.从远程clone一个项目 git clone ‘项目地址’ //clone项目地 git checkout -b dev origin/dev //远程已有dev分支,新建本地dev分支与远程相对 ...

  4. mysql第四篇:数据操作之单表查询

    单表查询 一.简单查询 -- 创建表 DROP TABLE IF EXISTS `person`; CREATE TABLE `person` ( `id` ) NOT NULL AUTO_INCRE ...

  5. java 微信红包算法代码实现及架构设计

    转载至:https://www.zybuluo.com/yulin718/note/93148 微信红包的架构设计简介 架构 @来源于QCon某高可用架构群整理,整理朱玉华. 背景:有某个朋友在朋友圈 ...

  6. POJ 1519:Digital Roots

    Digital Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25766   Accepted: 8621 De ...

  7. UVA 11552 序列划分模型 状态设计DP

    这个题目刚看到还真不好下手,把一个是 k的倍数的长度的字符串分成len/k块,每块是k个字母,每个块可以重新组合,最后使得整个序列的相同字母尽量在一起,也就是说,最后会把序列从前往后扫,相连的相同字母 ...

  8. vue样式的动态绑定

    true显示样式,flase不显示 <!DOCTYPE html> <html lang="en"> <head> <meta chars ...

  9. 吴裕雄--天生自然Django框架开发笔记:Django简介

    Python下有许多款不同的 Web 框架.Django是重量级选手中最有代表性的一位.许多成功的网站和APP都基于Django. Django是一个开放源代码的Web应用框架,由Python写成. ...

  10. dp高难本攻略

    903. DI 序列的有效排列 public int numPermsDISequence(String S) { int n=S.length(); int [][]dp=new int [n+1] ...