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 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(贪心)的更多相关文章
- 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 ...
- 2018 ACM ICPC 南京赛区 酱油记
Day 1: 早上6点起床打车去车站,似乎好久没有这么早起床过了,困到不行,在火车上睡啊睡就睡到了南京.南航离南京南站很近,地铁一站就到了,在学校里看到了体验坐直升机的活动,感觉很强.报道完之后去吃了 ...
- 2018 ACM/ICPC 南京 I题 Magic Potion
题解:最大流板题:增加两个源点,一个汇点.第一个源点到第二个源点连边,权为K,然后第一个源点再连其他点(英雄点)边权各为1,然后英雄和怪物之间按照所给连边(边权为1). 每个怪物连终点,边权为1: 参 ...
- Codeforces - 102222H - Fight Against Monsters - 贪心
https://codeforc.es/gym/102222/problem/H 题意:有一堆怪兽,怪兽有HP和ATK.你有一个英雄,英雄每次先被所有怪兽打,然后打其中一个怪兽.打的伤害递增,第一次1 ...
- 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 ...
- 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛
比赛链接: http://202.197.224.59/OnlineJudge2/index.php/Contest/problems/contest_id/36 题目来源: 2014嘉杰信息杯ACM ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- linux 用户与文件常用命令
用户与文件 su :切换到超级用户 su - l chesney : 切换到chesney用户 sudo usermod -G sudo -a chesney:把chesney 加入到sudo组 su ...
- 一天一个设计模式——工厂方法(FactoryMethod)模式
一.模式说明 在前一个模板方法(Template Method)模式中,父类定义了处理流程,而流程中用到的方法交给子类去实现.类似的,在工厂方法模式中,父类决定如何生成实例,但并不决定所要生成的具体类 ...
- XML--XML概览
参考 https://www.cnblogs.com/fangjian0423/p/xml-namespace.html http://www.w3school.com.cn/x.asp xmlns ...
- PHP集成环境wamp和navicat for mysql 的安装
1. PHP集成环境WAMP的安装: 下载wamp: 链接:https://pan.baidu.com/s/1zvoPEbLdG7y04WWHNM6UcA 密码:mxd3 安装过程如下图: 安装完成 ...
- 对自己有用的VS调试技巧
设置下一条语句 编辑然后继续 符号越界后查看堆对象 查看数组的值 底部 设置下一条语句 返回顶部 一个典型的调试情况就是通过单步跟踪分析为什么一个函数调用失败了.当你发现一个函数调用的另一个函数返回错 ...
- MySQL读写分离如何实现?
主要说下读写分离, 当我们的数据量很大时,数据库服务器的压力变大,这时候我们需要从架构方面来解决这一问题,在一个网站中读的操作很多,写的操作很少,这时候我们需要配置读写分离,把读操作和写操作分离出来, ...
- input只允许输入数字,并且小数点后保留4位
<input type="text" value="" name="should_send_num" id="should_ ...
- 吴裕雄--天生自然MySQL学习笔记:MySQL UNION 操作符
MySQL UNION 操作符用于连接两个以上的 SELECT 语句的结果组合到一个结果集合中.多个 SELECT 语句会删除重复的数据. 语法 MySQL UNION 操作符语法格式: SELECT ...
- UML-包的设计
1.准则 1).准则1 包在水平和垂直划分上,要功能性内聚.即:同类关联功能的模块化,将参与共同目的.服务.协作.策略和功能的强相关类型(类或者接口)组织在一起. 如:在NextGen项目中,Pric ...
- Spring源码解读:核心类DefaultListableBeanFactory的继承体系
1 简介 我们常用的ClassPathXmlApplicationContext是AbstractRefreshableApplicationContext的子类,而DefaultListableBe ...