2019 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 nn 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 nn fierce and cruel monsters. The health point of the ii-th monster was HP_iHPi, and its attack value was ATK_iATKi.
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 kk (its health point would decrease by kk) 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 11, and the damage of Huriyyah's second attack to this monster was 22, the third time to this monster was 33, 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 TT indicating the number of test cases which is up to 10^3103.
For each test case, the first line contains an integers n (1 le n le 10^5)n(1≤n≤105) which is the number of monsters. The ii-th line of the following nn lines contains two integers HP_iHPi and ATK_i (1 le HP_i, ATK_i le 10^5)ATKi(1≤HPi,ATKi≤105) which describe a monster.
We guarantee that the sum of nn in all test cases is up to 10^6106.
Output
For each test case, output a line containing Case #x: y, where xx is the test case number starting from 11, and yy is the minimum amount of total damages the hero should suffer.
输出时每行末尾的多余空格,不影响答案正确性
样例输入复制
2
3
1 1
2 2
3 3
3
3 1
2 2
1 3
样例输出复制
Case #1: 19
Case #2: 14
这个题是一个贪心题,一开始使用的攻击力/血量作为贪心准则,然后样例能过,就在我要交的时候,队友说不同的HP杀死用的时间是一样的,所以这个题,确实是没读太懂题,在读了一遍题目,然后1A过了,题意举个生动的例子,时下最火的自走棋,对方上了一群大汉,现在你的德莱文畏畏缩缩的缩在角落,敌人的血量与攻击力不同,你攻击别人一下,然后所有人都打你一下,现在让你求怎样杀死所有人使得自己掉血最少。
#include<iostream>
#include<queue>
#include<algorithm>
#include<set>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<cstdio>
#include<cstring>
//---------------------------------Sexy operation--------------------------//
#define cini(n) scanf("%d",&n)
#define cinl(n) scanf("%lld",&n)
#define cinc(n) scanf("%c",&n)
#define cins(s) scanf("%s",s)
#define coui(n) printf("%d",n)
#define couc(n) printf("%c",n)
#define coul(n) printf("%lld",n)
#define debug(n) printf("%d_________________________________n",n);
#define speed ios_base::sync_with_stdio(0)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
//-------------------------------Actual option------------------------------//
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define Swap(a,b) a^=b^=a^=b
#define Max(a,b) (a>b?a:b)
#define Min(a,b) a<b?a:b
#define mem(n,x) memset(n,x,sizeof(n))
#define mp(a,b) make_pair(a,b)
#define pb(n) push_back(n)
#define dis(a,b,c,d) ((double)sqrt((a-c)*(a-c)+(b-d)*(b-d)))
//--------------------------------constant----------------------------------//
#define INF 0x3f3f3f3f
#define esp 1e-9
#define PI acos(-1)
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef long long ll;
//___________________________Dividing Line__________________________________/
struct PPP
{
int HP;
int GJ;
int Time;
}a[100010];
int num(int a)
{
int sum=0,cnt=1;
while(1)
{
sum++;
a=a-cnt++;
if(a<=0) return sum;
}
}
bool cmp(PPP a,PPP b)
{
return a.Time*b.GJ<b.Time*a.GJ;
}
int main()
{
int t,k=0;
scanf("%d",&t);
while(k++<t)
{
int n,i;
scanf("%d",&n);
for(i=0;i<n;i++)
{
cini(a[i].HP),cini(a[i].GJ);
a[i].Time=num(a[i].HP);
}
sort(a,a+n,cmp);
ll sum=0,cnt=0;
for(i=0;i<n;i++)
{
cnt+=a[i].Time;
sum+=cnt*a[i].GJ;
}
printf("Case #%d: %lldn",k,sum);
}
return 0;
}
- Android性能优化篇:使用软引用和弱引用
- 使用泛型委托,构筑最快的通用属性访问器
- 记录容易忘记的方法
- 无需重新编译代码,在线修改表单
- 使用反射+缓存+委托,实现一个不同对象之间同名同类型属性值的快速拷贝
- 结构变量作为方法的参数调用,在方法内部使用的“坑”你遇到过吗?
- 使用表达式树,让访问者直接执行“角色”对象的方法
- 【更正】“给自定义控件(Web Control)添加事件的几种方法”有一个不太准确的地方。
- 在数据库上实现类似铁路售票锁票功能
- Android代码判断手机是否已root方法学习
- 实体类的枚举属性--原来支持枚举类型这么简单,没有EF5.0也可以
- Android中Context用法详解学习
- 【自然框架】之 “表单控件”与“实体类”
- Android数据存储实现的5大方式
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 两个字数字字符串求和
- 设计模式(二):Android 源码中的工厂模式
- MoveIt!之ROS1Melodic版本发布(MoveItCpp教程)
- 机器学习第1天:线性回归(代码篇)
- PHP二分查找
- OnClick 的另一种书写
- JVM系列之:JIT中的Virtual Call
- 速读原著-UnixLinux基础(五)
- Celery在Django中的简单应用
- 基于数据库Binlog 的业务系统操作日志实现方案(阿里中间件Canal)
- 速读原著-UnixLinux基础(三)
- 手撸实现UDP和TCP通信
- 3分钟短文 | PHP获取函数参数名,和类定义的常量,都要反射!
- 3分钟短文 | Laravel模型获取最后一条插入记录的ID编号
- 3分钟短文 | Laravel 模型的get find first方法你分清咋用了吗?