Codeforces - 102222H - Fight Against Monsters - 贪心
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 - 贪心的更多相关文章
- Codeforces 1296D - Fight with Monsters
题目大意: n 只怪兽,每只的血量为 h[i] ,你的攻击力为 a ,你的对手攻击力为 b 打每只怪兽时,都是你先出手,然后你的对手出手,这样轮流攻击 如果是你给予了怪兽最后一击,你就能得到一分 你还 ...
- Codeforces Round #617 (Div. 3) D. Fight with Monsters
D : Fight with Monsters 题目大意 : 有一组数,每个值对应着一个怪物的 hp 值,现在有两个人,一个自己一个对手,每个人有一个攻击值, 两个人轮流攻击怪物,如果是自己将怪物先打 ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- D. Fight with Monsters
D. Fight with Monsters time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 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 ...
- Fight Against Monsters Gym - 102222H【贪心】
贪心的策略 #include <bits/stdc++.h> using namespace std; ; typedef long long ll; struct m { int hp, ...
- 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 ...
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
随机推荐
- 前端框架之VUE
vue学习[第1篇]:vue之指令 vue学习[第2篇]:es6简单介绍 vue学习[第3篇]:vue之node.js的简单介绍 vue学习[第4篇]:vue 之webpack打包工具的使用 vue学 ...
- node.js抓取网上图片保存到本地
用到两个模块,http和fs var http = require("http");var fs = require("fs"); var server = h ...
- TCP/IP 详解卷一 - TCP CWR、ECE、URG、ACK、PSH、RST、SYN、FIN控制位
from:https://blog.csdn.net/u012243115/article/details/43487461 2015年02月04日 15:56:32 阅读数:1464 TCP 和 U ...
- [原创]Java开发在线编辑Word同时实现全文检索
一.背景介绍 Word文档与日常办公密不可分,在实际应用中,当某一文档服务器中有很多Word文档,假如有成千上万个文档时,用户查找打开包含某些指定关键字的文档就变得很困难,一般情况下能想到的解决方案是 ...
- codeforces 631C C. Report
C. Report time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- 【leetcode刷题笔记】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- 【leetcode刷题笔记】N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...
- 基于v4l2 ffmpeg x264的视频远程监控(附上编译好的库文件)
说明:主要是基于ghostyu网友整理的< arm mini2440 基于v4l2 ffmpeg x264的视频远程监控>.自己做了一遍,遇到不少问题,就整理记录下来. 1.平台 硬件:a ...
- 用nginx搭建http/rtmp/hls协议的MP4/FLV流媒体服务器
前前后后搭建了两三个星期,终于可以告一段落,nginx实在是有点强大.写一篇笔记来记录一下这个过程中的思路和解决方案. 一.搭建nginx平台: 基本是基于http://blog.csdn.net/x ...
- 1057 Stack (30)(30 分)
Stack is one of the most fundamental data structures, which is based on the principle of Last In Fir ...