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 ...
随机推荐
- RPC和RabbitMQ
在单台机器或者单个进程中,如果要调用某个函数,只需要通过函数指针,传入相关参数,即可调用成功并获得结果.但如果是在分布式系统中,某个进程想要调用远程机器上的其它进程提供的方法(服务),就需要采用RPC ...
- nodepad++ 标签栏无法拖放标签
nodepad++ 标签栏无法拖放标签设置--首选项--常用--标签栏--锁定(不允许拖放) 去掉这个勾 ps:最近版本的不知道为什么这个设置不生效了,没找到原因,可能是bug,只能等待升级解决了(升 ...
- 5+App使用定位
1.定位方法 5+App定位方法:5+ API中的Geolocation模块 Geolocation目前支持h5内置的定位,百度,高德.h5内置定位支持wgs84坐标系:百度支持gcj ...
- JavaScript中几种 获取元素的方式
1.根据id获取元素 document.getElementById("id属性的值"); 2.根据标签名字获取元素 document.getElementsByTagName(& ...
- cojs DAG计数问题1-4 题解报告
最近突然有很多人来问我这些题目怎么做OwO 然而并不是我出的,结论我也不是很懂 研究了一下觉得非常的一颗赛艇,于是就打算写这样一篇题解 DAG 1 我们考虑DAG的性质,枚举出度为0的点 设出度为0的 ...
- 使用wireshark分析tcp/ip报文之报文头
以太网报文的结构如下: 其中,以太网的帧头: 14 Bytes:MAC目的地址48bit(6B),MAC源地址48bit(6B),Type域2B,一共14B. IP头部: TCP头部: http:// ...
- SQL、SQL Server、MySQL与Oracle
SQL (Structured Query Language),结构化查询语言,用来与多种数据库建立联系,根据ANSI(美国国家标准协会)的规定,SQL为RDBMS(关系型数据库)的标准语言. --- ...
- CF#235E. Number Challenge
传送门 可以理解为上一道题的扩展板.. 然后我们就可以YY出这样一个式子 ${\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^cd(ijk)=\sum_{i=1}^a\sum_{ ...
- CodeForces 76A Gift - 最小生成树
The kingdom of Olympia consists of N cities and M bidirectional roads. Each road connects exactly tw ...
- [noip模拟题]科技节 - 搜索 - 位运算优化
[问题描述] 一年一度的科技节即将到来.同学们报名各项活动的名单交到了方克顺校长那,结果校长一看皱了眉头:这帮学生热情竟然如此高涨,每个人都报那么多活动,还要不要认真学习了?!这样不行!……于是,校长 ...