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

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

乱码:

  1. //#pragma comment(linker,"/STACK:1024000000,1024000000")
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<string>
  5. #include<cstring>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<stack>
  10. #include<map>
  11. #include<set>
  12. #include<algorithm>
  13. #include <stack>
  14. #include <list>
  15. using namespace std;
  16. const int SZ=,INF=0x7FFFFFFF;
  17. typedef long long lon;
  18. const double EPS=1e-;
  19.  
  20. int main()
  21. {
  22. std::ios::sync_with_stdio();
  23. //freopen("d:\\1.txt","r",stdin);
  24. int hy,ay,dy,hm,am,dm,a,b,c;
  25. cin>>hy>>ay>>dy>>hm>>am>>dm>>a>>b>>c;
  26. int lo=;int hi=,res=INF;
  27. for(int mid=;mid<;++mid)
  28. {
  29. //int mid=(lo+hi)/2;
  30. bool ok=;
  31. for(int i=;i<=mid;++i)
  32. {
  33. //if(i>100)cout<<i<<endl;
  34. for(int j=;j<=mid&&i+j<=mid;++j)
  35. {
  36. //if(mid>100)cout<<mid<<endl;
  37. //if(i==100&&j)cout<<j<<endl;
  38. int hc=,ac=ay+i,dc=dy+j;
  39. int curcost=b*i+c*j;
  40. int mhurt=max(,am-dc);
  41. int yhurt=max(,ac-dm);
  42. if(mhurt==&&yhurt!=)
  43. {
  44. ok=;
  45. res=min(res,curcost);
  46. //if(res==6289)cout<<i<<" "<<j<<" "<<k<<endl;
  47. }
  48. else if(mhurt&&yhurt)
  49. {
  50. int hlo=,hhi=1e5+;
  51. int oldcost=curcost;
  52. for(;hlo<hhi;)
  53. {
  54. int innerok=;
  55. int hmid=(hlo+hhi)/;
  56. int hc=hy+hmid;
  57. int coin=(hc%(am-dc)==);
  58. int hit=hc/(am-dc);
  59. if(coin)--hit;
  60. int mend=hm/(ac-dm)+(hm%(ac-dm)!=);
  61. if(hit>=mend)
  62. {
  63. curcost=oldcost+hmid*a;
  64. ok=;
  65. innerok=;
  66. res=min(res,curcost);
  67. //if(res==6289)cout<<i<<" "<<j<<" "<<k<<endl;
  68. }
  69. if(innerok)hhi=hmid;
  70. else hlo=hmid+;
  71. }
  72. }
  73. }
  74. }
  75. //cout<<mid<<" "<<ok<<endl;
  76. if(ok)hi=mid;
  77. else lo=mid+;
  78. }
  79. cout<<res<<endl;
  80. return ;
  81. }

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. RPC和RabbitMQ

    在单台机器或者单个进程中,如果要调用某个函数,只需要通过函数指针,传入相关参数,即可调用成功并获得结果.但如果是在分布式系统中,某个进程想要调用远程机器上的其它进程提供的方法(服务),就需要采用RPC ...

  2. nodepad++ 标签栏无法拖放标签

    nodepad++ 标签栏无法拖放标签设置--首选项--常用--标签栏--锁定(不允许拖放) 去掉这个勾 ps:最近版本的不知道为什么这个设置不生效了,没找到原因,可能是bug,只能等待升级解决了(升 ...

  3. 5+App使用定位

    1.定位方法     5+App定位方法:5+ API中的Geolocation模块     Geolocation目前支持h5内置的定位,百度,高德.h5内置定位支持wgs84坐标系:百度支持gcj ...

  4. JavaScript中几种 获取元素的方式

    1.根据id获取元素 document.getElementById("id属性的值"); 2.根据标签名字获取元素 document.getElementsByTagName(& ...

  5. cojs DAG计数问题1-4 题解报告

    最近突然有很多人来问我这些题目怎么做OwO 然而并不是我出的,结论我也不是很懂 研究了一下觉得非常的一颗赛艇,于是就打算写这样一篇题解 DAG 1 我们考虑DAG的性质,枚举出度为0的点 设出度为0的 ...

  6. 使用wireshark分析tcp/ip报文之报文头

    以太网报文的结构如下: 其中,以太网的帧头: 14 Bytes:MAC目的地址48bit(6B),MAC源地址48bit(6B),Type域2B,一共14B. IP头部: TCP头部: http:// ...

  7. SQL、SQL Server、MySQL与Oracle

    SQL (Structured Query Language),结构化查询语言,用来与多种数据库建立联系,根据ANSI(美国国家标准协会)的规定,SQL为RDBMS(关系型数据库)的标准语言. --- ...

  8. CF#235E. Number Challenge

    传送门 可以理解为上一道题的扩展板.. 然后我们就可以YY出这样一个式子 ${\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^cd(ijk)=\sum_{i=1}^a\sum_{ ...

  9. CodeForces 76A Gift - 最小生成树

    The kingdom of Olympia consists of N cities and M bidirectional roads. Each road connects exactly tw ...

  10. [noip模拟题]科技节 - 搜索 - 位运算优化

    [问题描述] 一年一度的科技节即将到来.同学们报名各项活动的名单交到了方克顺校长那,结果校长一看皱了眉头:这帮学生热情竟然如此高涨,每个人都报那么多活动,还要不要认真学习了?!这样不行!……于是,校长 ...