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 ...
随机推荐
- 性能分析之– JAVA Thread Dump 分析
最近在做性能测试,需要对线程堆栈进行分析,在网上收集了一些资料,学习完后,将相关知识整理在一起,输出文章如下. 一.Thread Dump介绍 1.1什么是Thread Dump? Thread Du ...
- 调用spark API,监控任务的进度
我们现在需要监控datapre0这个任务每一次执行的进度,操作如下: 1. 如图所示,打开spark管理页面,找到对应的任务,点击任务名datapre0 2. 进去之后,获得对应IP和端口 3. 访 ...
- yum hosts
67.219.148.138 mirrorlist.centos.org202.38.97.230 ftp.sjtu.edu.cn202.121.199.235 mirrors.shu.edu.cn2 ...
- android 图片大小适配,如何在不同屏幕上适配图片,如何设置可以自适应不同分辨率?
android 图片大小适配,如何在不同屏幕上适配图片,如何设置可以自适应不同分辨率? Android为了适应不同的分辨率,需要将不同的图片放到不同的drawable目录下,分辨率的匹配规则如下:dr ...
- JMeter:全面的乱码解决方案
中文乱码一直都是比较让人棘手的问题,我们在使用Jmeter的过程中,也会遇到中文乱码问题 接口:http://127.0.0.1:8090/test 这个接口有一个参数name,返回结果就是你传的na ...
- bzoj1704 / P2882 [USACO07MAR]面对正确的方式Face The Right Way
P2882 [USACO07MAR]面对正确的方式Face The Right Way $n<=5000$?枚举翻转长度,顺序模拟就ok了 对于每次翻转,我们可以利用差分的思想,再搞搞前缀和. ...
- Linux下useradd命令创建的用户不能登录的问题
Linux下useradd命令创建的用户不能登录的问题 问题: 用useradd命令新创建一个用户tester 密码pwdtest mkdir -p /home/tester(创建文件夹) user ...
- Android 拖动条 和 Handle
- linux一键安装包
- Delphi XE5 for Android (五)
Android程序开发必然用到按钮,在XE5下,按钮的一个比较重要的属性就是StyleLookup,预置了一系列常用的图标,如下图: 另外2个常用属性就是: GroupName和IsPressed:一 ...