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 ...
随机推荐
- Spring Boot without the web server
https://stackoverflow.com/questions/26105061/spring-boot-without-the-web-server/28565277 1. spring.m ...
- 2,StructuredStreaming的事件时间和窗口操作
推荐阅读:1,StructuredStreaming简介 使用Structured Streaming基于事件时间的滑动窗口的聚合操作是很简单的,很像分组聚合.在一个分组聚合操作中,聚合值被唯一保存在 ...
- PAT 2018 秋
A 1148 Werewolf - Simple Version 思路比较直接:模拟就行.因为需要序列号最小的两个狼人,所以以狼人为因变量进行模拟. #include <cstdio> # ...
- 强制浏览器以IE8版本运行
做为一个开发人员,经常被要求前端页面兼容ie8及以上,所以有时候我们希望ie默认以ie8的版本打开我们的页面. 1.“文档模式”: 在html页面中加入类似下面的代码: <meta http-e ...
- Leetcode第1题:两数之和
给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的 两个 整数.你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组中同样的元素.示例:给定 nums ...
- (函数)P1149 火柴棒等式
题解: #include<stdio.h>int a[10]={6,2,5,5,4,5,6,3,7,6};int num(int n){ ...
- epoll机制
一.参考网址 1.epoll机制:epoll_create.epoll_ctl.epoll_wait.close 2.Linux网络编程 使用epoll实现一个高性能TCP Echo服务器 3.用C写 ...
- css清除select的下拉箭头样式
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> ...
- python 文件练习
# 注册:# 1.账号.密码存到文件# 2.判断输入是否为空# 3.校验用户是否存在# 4.用户名和密码长度在6-12位之间#将文件读取到字典中def get_users(): f = open('1 ...
- 黑马IDEA版javaweb_2-1基础加强
今日内容 1. Junit单元测试 2. 反射 3. 注解 ## Junit单元测试: * 测试分类: 1. 黑盒测试:不需要写代码,给输入值,看程序是否能够输出期望的值. 2. 白盒测试:需要写代码 ...