codeforces 487a//Fight the Monster// Codeforces Round #278(Div. 1)
题意:打怪兽。可增加自己的属性,怎样在能打倒怪兽的情况下花费最少?
这题关键要找好二分的量。一开始我觉得,只要攻击到101,防御到100,就能必胜,于是我对自己的三个属性的和二分(0到201),内部三层循环(最多到不了200*200*200)。1秒内能过。不过发现如果生命值很便宜,防御很贵的话,买生命值合算。10100点生命值就能必赢,于是上界调为10100,超时。
后来就想,二分攻击(记为i)和防御(记为j)的和mid,内部二重循环列出i+j=mid的所有情况。再单独二分生命值k,如果ijk的组合能打倒怪兽,再缩小k的值,再判断。不过这样做的话最外层应该枚举而不是二分。复杂度是200*200*200*log(10000),上面那种做法是10000*10000*10000*log(10000)。
乱码:
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
const double EPS=1e-; int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
int hy,ay,dy,hm,am,dm,a,b,c;
cin>>hy>>ay>>dy>>hm>>am>>dm>>a>>b>>c;
int lo=;int hi=,res=INF;
for(int mid=;mid<;++mid)
{
//int mid=(lo+hi)/2;
bool ok=;
for(int i=;i<=mid;++i)
{
//if(i>100)cout<<i<<endl;
for(int j=;j<=mid&&i+j<=mid;++j)
{
//if(mid>100)cout<<mid<<endl;
//if(i==100&&j)cout<<j<<endl;
int hc=,ac=ay+i,dc=dy+j;
int curcost=b*i+c*j;
int mhurt=max(,am-dc);
int yhurt=max(,ac-dm);
if(mhurt==&&yhurt!=)
{
ok=;
res=min(res,curcost);
//if(res==6289)cout<<i<<" "<<j<<" "<<k<<endl;
}
else if(mhurt&&yhurt)
{
int hlo=,hhi=1e5+;
int oldcost=curcost;
for(;hlo<hhi;)
{
int innerok=;
int hmid=(hlo+hhi)/;
int hc=hy+hmid;
int coin=(hc%(am-dc)==);
int hit=hc/(am-dc);
if(coin)--hit;
int mend=hm/(ac-dm)+(hm%(ac-dm)!=);
if(hit>=mend)
{
curcost=oldcost+hmid*a;
ok=;
innerok=;
res=min(res,curcost);
//if(res==6289)cout<<i<<" "<<j<<" "<<k<<endl;
}
if(innerok)hhi=hmid;
else hlo=hmid+;
}
}
}
}
//cout<<mid<<" "<<ok<<endl;
if(ok)hi=mid;
else lo=mid+;
}
cout<<res<<endl;
return ;
}
codeforces 487a//Fight the Monster// Codeforces Round #278(Div. 1)的更多相关文章
- Codeforces Round #278 (Div. 1) A. Fight the Monster 暴力
A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/ ...
- Codeforces Round #278 (Div. 2)
题目链接:http://codeforces.com/contest/488 A. Giga Tower Giga Tower is the tallest and deepest building ...
- Codeforces 488C Fight the Monster
Fight the Monster time limit per test 1 second memory ...
- Codeforces Round #278 (Div. 1) B. Strip multiset维护DP
B. Strip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/B De ...
- Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)
B. Candy Boxes Problem's Link: http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. ana ...
- CodeForces Round #278 (Div.2) (待续)
A 这么简单的题直接贴代码好了. #include <cstdio> #include <cmath> using namespace std; bool islucky(in ...
- Codeforces Round #278 (Div. 1)
A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang an ...
- Codeforces Round #278 (Div. 2) D. Strip 线段树优化dp
D. Strip time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #278 (Div. 1) D - Conveyor Belts 分块+dp
D - Conveyor Belts 思路:分块dp, 对于修改将对应的块再dp一次. #include<bits/stdc++.h> #define LL long long #defi ...
随机推荐
- 怎么查看是否安装Scrapy
1.在python shell 下输入 import scrapy
- Java设计模式应用——过滤器模式
storm引擎计算出一批中间告警结果,会发送一条kafka消息给告警入库服务,告警入库服务接收到kafka消息后读取中间告警文件,经过一系列处理后把最终告警存入mysql中. 实际上,中间告警结果可能 ...
- Ajax jquery的库的简化版本
Ajax jquery的库的简化版本 (function(){ //面向外界的唯一变量接口! var myajax = window.myajax = {}; //作者.版本号等等信 ...
- 根据wsdl,apache cxf的wsdl2java工具生成客户端、服务端代码
根据wsdl,apache cxf的wsdl2java工具生成客户端.服务端代码 apache cxf的wsdl2java工具的简单使用: 使用步骤如下: 一.下载apache cxf的包,如apac ...
- Harmonic Number (调和级数+欧拉常数)题解
Harmonic Number In mathematics, the nth harmonic number is the sum of the reciprocals of the first n ...
- BZOJ2563: 阿狸和桃子的游戏 贪心
Description 阿狸和桃子正在玩一个游戏,游戏是在一个带权图G=(V, E)上进行的,设节点权值为w(v),边权为c(e).游戏规则是这样的: 1. 阿狸和桃子轮流将图中的顶点染色,阿狸会将顶 ...
- Python实现自平衡二叉树AVL
# -*- coding: utf-8 -*- from enum import Enum #参考http://blog.csdn.net/niteip/article/details/1184069 ...
- HDU 2242 考研路茫茫——空调教室(边双连通分量+树形dp+重边标号)
http://acm.hdu.edu.cn/showproblem.php?pid=2242 题意: 思路:首先求一下双连通分量,如果只有一个双连通分量,那么无论断哪根管子,图还是连通的. 最后只需要 ...
- LA 3135 阿格斯(优先队列)
https://vjudge.net/problem/UVALive-3135 题意: 你的任务是编写一个称为Argus的系统.该系统支持一个Register的命令 Register Q_num Pe ...
- BZOJ4896 [Thu Summer Camp2016]补退选
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...