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 ...
随机推荐
- VNC的安装和常用命令
主要参考文章:http://www.cnblogs.com/coderzh/archive/2008/07/16/1243990.html http:/ ...
- 20145316《网络对抗》Exp9 Web安全基础实践学习总结
20145316<网络对抗>Exp9 Web安全基础实践学习总结 基础问题回答 SQL注入攻击原理,如何防御 SQL注入,就是攻击者通过把SQL命令插入到Web表单递交或输入域名或页面请求 ...
- php header utf8 插入header("Content-type: text/html; charset=utf-8");
PHP文件插入header("Content-type: text/html; charset=utf-8"); 相当于页面里面的<meta http-equiv=" ...
- jquery基础框架
(function(window,undefined){ var arr = [], push = arr.push, slice = arr.slice; //首先要做的就是封装一个parseHtm ...
- Linux解压文件到指定目录
Linux解压文件到指定目录 tar在Linux上是常用的打包.压缩.加压缩工具,他的参数很多,折里仅仅列举常用的压缩与解压缩参数 参数:-c :create 建立压缩档案的参数:-x : 解压缩压缩 ...
- EF 一个实体对象不能由多个 IEntityChangeTracker 实例引用 解决办法
在DAL层中,建立工厂类 namespace DAL { public static class SysDbContextFactory { /// <summary> /// 从Http ...
- JavaScript 中语法规范及调试
JavaScript 中语法规范及调试 版权声明:未经博主授权,内容严禁分享转载 JavaScript 开发环境 JavaScript 脚本可以使用任意一款纯文本编辑器进行编程开发. 常见的前端开发编 ...
- 04: linux基础总结
目录: 1.1 Red Hat Linux 安装及服务控制 1.2 目录和文件管理 1.3 安装及管理程序 1.4 账号和权限管理 1.5 磁盘和文件管理 1.6 进程和计划任务管理 1.7 Linu ...
- jQuery 源码分析:当 selector 传来一个函数时,怎么进行处理?
本文章为 0.9 版本,将会在稍后润色更新.本文使用的 jQuery 版本为 3.4.0 我们知道使用 $ 操作符时,可以往里面塞很多类型的参数,字符串,对象,函数...,jQuery 会根据不同的参 ...
- v-bind绑定属性样式
一.class的四种绑定方式 1.布尔值的绑定方式 <div id="demo"> <span v-bind:class="{'class-a':isA ...