题意:打怪兽。可增加自己的属性,怎样在能打倒怪兽的情况下花费最少?

这题关键要找好二分的量。一开始我觉得,只要攻击到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)的更多相关文章

  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/ ...

  2. Codeforces Round #278 (Div. 2)

    题目链接:http://codeforces.com/contest/488 A. Giga Tower Giga Tower is the tallest and deepest building ...

  3. Codeforces 488C Fight the Monster

    Fight the Monster time limit per test             1 second                                   memory ...

  4. 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 ...

  5. 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 ...

  6. CodeForces Round #278 (Div.2) (待续)

    A 这么简单的题直接贴代码好了. #include <cstdio> #include <cmath> using namespace std; bool islucky(in ...

  7. Codeforces Round #278 (Div. 1)

    A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang an ...

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

  9. Codeforces Round #278 (Div. 1) D - Conveyor Belts 分块+dp

    D - Conveyor Belts 思路:分块dp, 对于修改将对应的块再dp一次. #include<bits/stdc++.h> #define LL long long #defi ...

随机推荐

  1. mysql索引使用策略及优化

    原文地址:http://blog.codinglabs.org/articles/theory-of-mysql-index.html 索引使用策略及优化 MySQL的优化主要分为结构优化(Schem ...

  2. 【tensorflow】pip 安装失败的原因

    linux系统旧版本:   pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27- ...

  3. 更改 Centos 6 的 yum 源

    1.查看当前使用的源: yum repolist all 阿里源网址,使用方法点右边的帮助可以看到:https://opsx.alibaba.com/mirror 2.更改源: 第一步:备份你的原镜像 ...

  4. 使用requireJS加载不符合AMD规范的js文件:shim的使用方式和实现原理

    原文链接: http://www.bubuko.com/infodetail-671521.html

  5. tomcat部署项目如何去掉项目名称

    去掉项目名和端口: 首先,进入tomcat的安装目录下的conf目录,我的目录是 /usr/local/apache-tomcat-6.0.20/conf,编辑文件server.xml. 1.去除端口 ...

  6. U盘+GRUB2引导PE或linux镜像

    利用U盘制作启动盘,引导WinPE.Linux安装的文章多如牛毛,与他们相比本文的特点有: 1.用且仅用grbu2做引导.不使用grub4dos,不是使用msdos mbr转到活动分区,到ntldr, ...

  7. linux下设置软件使用socks5代理

    1.为wget使用代理,可以直接修改/etc/wgetrc,也可以在主文件夹下新建.wgetrc,并编辑相应内容,本文采用后者. 直接往~/.wgetrc(自行创建此文件)添加如下内容: https_ ...

  8. CSU 1805 Three Capitals(矩阵树定理+Best定理)

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1805 题意: A和B之间有a条边,A和G之间有b条边,B和G之间有c条边.现在从A点出发走遍所 ...

  9. C# asp.net 比较两个时间的差求天数

    string str1 = "2017-2-13 23:59:59"; string str2 = "2017-2-14 0:00:01"; DateTime ...

  10. Linux——bash应用技巧简单学习笔记

    本人是看的lamp兄弟连的视频,学习的知识做一下简单,如有错误尽情拍砖. 命令补齐 命令补齐允许用户输入文件名起始的若干个字 母后,按<Tab>键补齐文件名. 命令历史 命令历史允许用户浏 ...