题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFnoi%E8%80%83%E5%90%8E%E6%AC%A2%E4%B9%90%E8%B5%9B%29/%E4%B9%8C%E9%B8%A6%E5%96%9D%E6%B0%B4

题解:真是一道神题!考场上绝对想不到标算orz!

题解写在代码注释里

代码:

  1. #include<cstdio>
  2.  
  3. #include<cstdlib>
  4.  
  5. #include<cmath>
  6.  
  7. #include<cstring>
  8.  
  9. #include<algorithm>
  10.  
  11. #include<iostream>
  12.  
  13. #include<vector>
  14.  
  15. #include<map>
  16.  
  17. #include<set>
  18.  
  19. #include<queue>
  20.  
  21. #include<string>
  22.  
  23. #define inf 1000000000
  24.  
  25. #define maxn 100000+5
  26.  
  27. #define maxm 500+100
  28.  
  29. #define eps 1e-10
  30.  
  31. #define ll long long
  32.  
  33. #define pa pair<int,int>
  34.  
  35. #define for0(i,n) for(int i=0;i<=(n);i++)
  36.  
  37. #define for1(i,n) for(int i=1;i<=(n);i++)
  38.  
  39. #define for2(i,x,y) for(int i=(x);i<=(y);i++)
  40.  
  41. #define for3(i,x,y) for(int i=(x);i>=(y);i--)
  42.  
  43. #define mod 1000000007
  44.  
  45. using namespace std;
  46.  
  47. inline int read()
  48.  
  49. {
  50.  
  51. int x=,f=;char ch=getchar();
  52.  
  53. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  54.  
  55. while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
  56.  
  57. return x*f;
  58.  
  59. }
  60. int n,m,h,s[maxn],a[maxn],b[maxn],id[maxn];
  61. inline void add(int x,int y){for(;x<=n;x+=x&(-x))s[x]+=y;}
  62. inline int sum(int x){int t=;for(;x;x-=x&(-x))t+=s[x];return t;}
  63. inline bool cmp(int x,int y){return b[x]==b[y]?x<y:b[x]<b[y];}
  64.  
  65. int main()
  66.  
  67. {
  68.  
  69. freopen("input","r",stdin);
  70.  
  71. freopen("output.txt","w",stdout);
  72.  
  73. n=read();m=read();h=read();
  74. for1(i,n)a[i]=read();
  75. for1(i,n)
  76. {
  77. int x=read();
  78. if(a[i]<=h)b[i]=(h-a[i])/x+;//b[i]表示该点最多可以被饮几次水
  79. if(b[i]>)add(i,);id[i]=i;
  80. }
  81. //可以证明,最后的答案一定是某个b[i],所以我们按b[i]从小到大处理
  82. sort(id+,id+n+,cmp);
  83. int now=,pos=,ans=,st=n+;//now 表示当前的趟数
  84. //for1(i,n)cout<<i<<' '<<id[i]<<' '<<b[i]<<endl;
  85. for1(i,n)if(b[id[i]]){st=i;break;}
  86. for2(i,st,n)
  87. {
  88. while(now<=m)
  89. {
  90. int t=sum(n)-sum(pos);
  91. if(ans+t<b[id[i]])ans+=t,now++,pos=;//如果可以走完这一趟
  92. else break;
  93. }
  94. if(now>m)break;
  95. int l=pos,r=n,t=sum(pos);
  96. while(l<=r)
  97. {
  98. int mid=(l+r)>>;
  99. if(sum(mid)-t+ans>=b[id[i]])r=mid-;else l=mid+;
  100. }//二分到下一个点
  101. ans=b[id[i]];pos=l;
  102. for(;b[id[i]]==b[id[i+]];i++)add(id[i],-);//去除不能再次饮水的点
  103. add(id[i],-);
  104. }
  105. printf("%d\n",ans);
  106.  
  107. return ;
  108.  
  109. }

Beta Round #9 (酱油杯noi考后欢乐赛)乌鸦喝水的更多相关文章

  1. Beta Round #9 (酱油杯noi考后欢乐赛)随机数生成器

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  2. Beta Round #9 (酱油杯noi考后欢乐赛)PLQ和他的小伙伴们

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  3. Beta Round #9 (酱油杯noi考后欢乐赛)PLQ的寻宝

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  4. Beta Round #9 (酱油杯noi考后欢乐赛)最大伤害

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  5. 洛谷---小L和小K的NOIP考后放松赛

    链接: https://www.luogu.org/contestnew/show/11805?tdsourcetag=s_pcqq_aiomsg 题解: 没人过的题我就没看 t2: 考虑每个点是朋友 ...

  6. Codeforces Beta Round #22 (Div. 2 Only)

    Codeforces Beta Round #22 (Div. 2 Only) http://codeforces.com/contest/22 A 水题 #include<bits/stdc+ ...

  7. Codeforces Beta Round #16 (Div. 2 Only)

    Codeforces Beta Round #16 (Div. 2 Only) http://codeforces.com/contest/16 A 水题 #include<bits/stdc+ ...

  8. Codeforces Beta Round #12 (Div 2 Only)

    Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...

  9. Codeforces Beta Round #57 (Div. 2)

    Codeforces Beta Round #57 (Div. 2) http://codeforces.com/contest/61 A #include<bits/stdc++.h> ...

随机推荐

  1. PHP和MYSQL的编码问题

    http://blog.csdn.net/martinkro/article/details/5352474 1 MYSQL中的字符集概念  Mysql的字符集里有两个概念,一个是"Char ...

  2. Oracle抓取表结构的语句

    oracle ---------------------------------------   SELECT case when t.COLUMN_ID=1 then t.table_name en ...

  3. DataTable.ImportRow()与DataTable.Rows.Add()的区别

    今天写代码的时候用到ImportRow()向DataTable中添加记录,代码如下: DataTable dt = datatable;DataRow dr = dt.NewRow();dr[&quo ...

  4. java新手笔记8 包

    1.main函数 public class MainParam { //考察main 方法的参数 args //运行时可以传入参数 参数类型 String public static void mai ...

  5. Druid 简单介绍

    官方网址:http://code.alibabatech.com/wiki/display/Druid/Home 1.什么是Druid Druid首先是一个数据库连接池.Druid是目前最好的数据库连 ...

  6. Codevs 4560 NOIP2015 D2T2 子串

    > 4560 NOIP2015 D2T2 子串 时间限制: 1 s 空间限制: 128000 KB 题目等级:黄金 Gold 题目描述 Description 有两个仅包含小写英文字母的字符串A ...

  7. .net开发人员等级

    .net 开发人员的瓶颈和职业发展 现在社会比前几年浮躁了,越来越多的人抱怨薪水低,高薪工作不好找; 诚然这有CPI的压力,可是也有很多人没有认清自己的职业发展. 很多.net程序员个各种纠结,想拿高 ...

  8. MongoDB笔记(五)深入学习

    系列一:http://www.cnblogs.com/huangxincheng/category/355399.html系列二:http://www.cnblogs.com/lipan/catego ...

  9. Linux Shell脚本之自动修改IP

    作为一名Linux SA,日常运维中很多地方都会用到脚本,而服务器的ip一般采用静态ip或者MAC绑定,当然后者比较操作起来相对繁琐,而前者我们可以设置主机名.ip信息.网关等配置.修改成特定的主机名 ...

  10. PL/SQL学习(三)游标

    原文参考:http://plsql-tutorial.com/ 两种类型:     隐式:         执行INSERT.UPDATE.DELETE 或者只返回一条结果的SELECT语句时默认创建 ...