https://codeforc.es/gym/102222/problem/H

题意:有一堆怪兽,怪兽有HP和ATK。你有一个英雄,英雄每次先被所有怪兽打,然后打其中一个怪兽。打的伤害递增,第一次1,第二次2,以此类推。

为什么感觉是贪心呢?证明一波。

首先开始打一个怪兽肯定一直打到死为止。那么打死他要求的次数可以二分出来(其实暴力也可以)。两只怪兽交换打的顺序会不会变好?

先打第一只怪兽:

\(num_1*sumatk+num_2*(sumatk-atk_1)\)

先打第二只怪兽:

\(num_2*sumatk+num_1*(sumatk-atk_2)\)

那么什么情况下先打第二只会更好呢?当然是上式大于下式:

\(num_1*sumatk+num_2*(sumatk-atk_1)>num_2*sumatk+num_1*(sumatk-atk_2)\)

化简:

\(num_1*atk_2>num_2*atk_1\)

当上式成立时需要交换。

插进优先队列里面一搞,又不会爆longlong。一波搞定。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; inline int read() {
int x=0;
int f=0;
char c;
do {
c=getchar();
if(c=='-')
f=1;
} while(c<'0'||c>'9');
do {
x=(x<<3)+(x<<1)+c-'0';
c=getchar();
} while(c>='0'&&c<='9');
return f?-x:x;
} inline void _write(int x) {
if(x>9)
_write(x/10);
putchar(x%10+'0');
} inline void write(int x) {
if(x<0) {
putchar('-');
x=-x;
}
_write(x);
putchar('\n');
} void TestCase(int ti); int main() {
#ifdef Yinku
freopen("Yinku.in","r",stdin);
//freopen("Yinku.out","w",stdout);
#endif // Yinku
int T=read();
for(int ti=1;ti<=T;ti++)
TestCase(ti);
} /*--- ---*/ inline int s1(int x){
return ((x+1)*x)>>1;
} struct Monster{
int hp;
int atk;
int num;
inline void calc(){
int l=1,r=1000,m;
while(1){
m=l+r>>1;
if(m==l){
int s=s1(l);
if(s>=hp){
num=l;
return;
}
else{
num=r;
return;
}
}
int s=s1(m);
if(s==hp){
num=m;
return;
}
else if(s<hp)
l=m+1;
else
r=m;
}
} inline bool operator<(const Monster &m)const{
return !(atk*m.num>=m.atk*num);
}
}monster; priority_queue<Monster> pq; void TestCase(int ti) {
ll sumatk=0;
int n=read();
for(int i=1;i<=n;i++){
monster.hp=read();
monster.atk=read();
sumatk+=monster.atk;
monster.calc();
pq.push(monster);
}
ll sumdamage=0;
while(!pq.empty()){
monster=pq.top();
pq.pop();
sumdamage+=sumatk*monster.num;
sumatk-=monster.atk;
}
printf("Case #%d: %lld\n",ti,sumdamage);
}

Codeforces - 102222H - Fight Against Monsters - 贪心的更多相关文章

  1. Codeforces 1296D - Fight with Monsters

    题目大意: n 只怪兽,每只的血量为 h[i] ,你的攻击力为 a ,你的对手攻击力为 b 打每只怪兽时,都是你先出手,然后你的对手出手,这样轮流攻击 如果是你给予了怪兽最后一击,你就能得到一分 你还 ...

  2. Codeforces Round #617 (Div. 3) D. Fight with Monsters

    D : Fight with Monsters 题目大意 : 有一组数,每个值对应着一个怪物的 hp 值,现在有两个人,一个自己一个对手,每个人有一个攻击值, 两个人轮流攻击怪物,如果是自己将怪物先打 ...

  3. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  4. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  5. D. Fight with Monsters

    D. Fight with Monsters time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. Codeforces #617 (Div. 3) D. Fight with Monsters(贪心,排序)

    There are nn monsters standing in a row numbered from 11 to nn . The ii -th monster has hihi health ...

  7. Fight Against Monsters Gym - 102222H【贪心】

    贪心的策略 #include <bits/stdc++.h> using namespace std; ; typedef long long ll; struct m { int hp, ...

  8. 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 Eg ...

  9. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

随机推荐

  1. github之克隆

    git clone --depth=10 git_仓库_url 只会获取最近 xx(10条提交记录的)代码,默认是master分支, 如果想要指定分支,可以结合 -b --single--branch ...

  2. Codeforces 366C Dima and Salad:背包dp

    题目链接:http://codeforces.com/problemset/problem/366/C 题意: 有n个物品,每个物品有两个属性a[i]和b[i]. 给定k,让你选出一些物品,使得 ∑ ...

  3. PHP限制IP访问 只允许指定IP访问 允许*号通配符过滤IP

    /** * 检测访问的ip是否为规定的允许的ip * Enter description here ... */ function check_ip(){ $ALLOWED_IP=array('192 ...

  4. 图像处理检测方法 — SIFT和SURF

    0.特征与匹配方法总结汇总对比 参考网址:http://simtalk.cn/2017/08/18/%E7%89%B9%E5%BE%81%E4%B8%8E%E5%8C%B9%E9%85%8D/#ORB ...

  5. npm-install once

    Once 是我最习惯的模块,它展示了几乎所有的我书写的通过issac Schlueter创建的应用. 原理很简单,Once使用各类一个函数且返回了一个函数,你可以调用这个函数,但是只能调用一次.如果你 ...

  6. Uva 10820 Send a Table(欧拉函数)

    对每个n,答案就是(phi[2]+phi[3]+...+phi[n])*2+1,简单的欧拉函数应用. #include<iostream> #include<cstdio> # ...

  7. ffmpeg混音(将多个声音合成一个)命令

    ffmpeg命令中可以使用filter amix实现这个功能. 官方文档 http://ffmpeg.org/ffmpeg-filters.html 6.8 amix Mixes multiple a ...

  8. 【C++ Primer 5th】Chapter 1

    1. 每个C++都包含至少一个函数,其中一个必须为main函数,且 main 函数的返回类型必须为 int. 2. 函数定义包括:返回类型,函数名,形参列表,函数体 3. main 函数返回值用来指示 ...

  9. [转]django 日志logging的配置以及处理

    http://davidbj.blog.51cto.com/4159484/1433741 日志在程序开发中是少不了的,通过日志我们可以分析到错误在什么地方,有什么异常.在生产环境下有很大的用途.在J ...

  10. 系列文章--AJAX技术系列总结

    各种AJAX方法的使用比较 用ASP.NET写个SQLSERVER的小工具  写自己的ASP.NET MVC框架(下)  写自己的ASP.NET MVC框架(上)  用Asp.net写自己的服务框架  ...