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

这题关键要找好二分的量。一开始我觉得,只要攻击到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. 比特币、莱特币钱包下载和把数据迁移到C盘以外其他盘

    比特币是目前最热门和价格最高的虚拟币,国内外多个平台可以进行交易,有些商家可以用比特币进行支付有些国家可以在ATM取款. Bitcoin-Qt就是最早的比特币客户端,构建了比特币的骨干网络,具有高度的 ...

  2. hue, saturation, and brightness:色调、饱和度和亮度

    色调.饱和度和亮度(hue, saturation, and brightness)以人对红.绿.蓝(RGB)三色组合的感觉为基础.在描述阴极射线管显示器参数时,经常提到这三个专有名词.所有的颜色可以 ...

  3. Linux用root强制踢掉已登录用户

    首先使用w命令查看所有在线用户: [root@VM_152_184_centos /]# w 20:50:14 up 9 days, 5:58, 3 users, load average: 0.21 ...

  4. 使用maven开发MR

    1.安装mvn(可以省略,因为eclipse自带maven插件) 1.1. 上传安装包到linux 1.2. 解压maven安装包 mkdir /usr/maven -bin.tar.gz -C /u ...

  5. Python3基础 str *运算 重复拼接字符串

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. Go第六篇之结构体剖析

    Go 语言通过用自定义的方式形成新的类型,结构体是类型中带有成员的复合类型.Go 语言使用结构体和结构体成员来描述真实世界的实体和实体对应的各种属性. Go 语言中的类型可以被实例化,使用new或&a ...

  7. win7 64位debug解决方法

    1.下载win 64位的DOSBox,如DOSBox0.74: 2.下载win 32 debug.exe,并复制到调用的目录,如d盘根目录d:\ 3.安装DOSBox,并运行:如下图: 4.键入命令: ...

  8. POJ3241 Object Clustering(最小生成树)题解

    题意:求最小生成树第K大的边权值 思路: 如果暴力加边再用Kruskal,边太多会超时.这里用一个算法来减少有效边的加入. 边权值为点间曼哈顿距离,那么每个点的有效加边选择应该是和他最近的4个象限方向 ...

  9. 51NOD 1069 Nim游戏

    1069 Nim游戏   有N堆石子.A B两个人轮流拿,A先拿.每次只能从一堆中取若干个,可将一堆全取走,但不可不取,拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出 ...

  10. v-model双向数据绑定

    v-model双向数据绑定的修饰符 .lazy:失去焦点时数据进行双向的绑定 v-model.lazy=”message ” .number:前面输入数字,后面接着字母自动去除掉.v-model. n ...