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%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!
题解写在代码注释里
代码:
- #include<cstdio>
- #include<cstdlib>
- #include<cmath>
- #include<cstring>
- #include<algorithm>
- #include<iostream>
- #include<vector>
- #include<map>
- #include<set>
- #include<queue>
- #include<string>
- #define inf 1000000000
- #define maxn 100000+5
- #define maxm 500+100
- #define eps 1e-10
- #define ll long long
- #define pa pair<int,int>
- #define for0(i,n) for(int i=0;i<=(n);i++)
- #define for1(i,n) for(int i=1;i<=(n);i++)
- #define for2(i,x,y) for(int i=(x);i<=(y);i++)
- #define for3(i,x,y) for(int i=(x);i>=(y);i--)
- #define mod 1000000007
- using namespace std;
- inline int read()
- {
- int x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
- return x*f;
- }
- int n,m,h,s[maxn],a[maxn],b[maxn],id[maxn];
- inline void add(int x,int y){for(;x<=n;x+=x&(-x))s[x]+=y;}
- inline int sum(int x){int t=;for(;x;x-=x&(-x))t+=s[x];return t;}
- inline bool cmp(int x,int y){return b[x]==b[y]?x<y:b[x]<b[y];}
- int main()
- {
- freopen("input","r",stdin);
- freopen("output.txt","w",stdout);
- n=read();m=read();h=read();
- for1(i,n)a[i]=read();
- for1(i,n)
- {
- int x=read();
- if(a[i]<=h)b[i]=(h-a[i])/x+;//b[i]表示该点最多可以被饮几次水
- if(b[i]>)add(i,);id[i]=i;
- }
- //可以证明,最后的答案一定是某个b[i],所以我们按b[i]从小到大处理
- sort(id+,id+n+,cmp);
- int now=,pos=,ans=,st=n+;//now 表示当前的趟数
- //for1(i,n)cout<<i<<' '<<id[i]<<' '<<b[i]<<endl;
- for1(i,n)if(b[id[i]]){st=i;break;}
- for2(i,st,n)
- {
- while(now<=m)
- {
- int t=sum(n)-sum(pos);
- if(ans+t<b[id[i]])ans+=t,now++,pos=;//如果可以走完这一趟
- else break;
- }
- if(now>m)break;
- int l=pos,r=n,t=sum(pos);
- while(l<=r)
- {
- int mid=(l+r)>>;
- if(sum(mid)-t+ans>=b[id[i]])r=mid-;else l=mid+;
- }//二分到下一个点
- ans=b[id[i]];pos=l;
- for(;b[id[i]]==b[id[i+]];i++)add(id[i],-);//去除不能再次饮水的点
- add(id[i],-);
- }
- printf("%d\n",ans);
- return ;
- }
Beta Round #9 (酱油杯noi考后欢乐赛)乌鸦喝水的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 洛谷---小L和小K的NOIP考后放松赛
链接: https://www.luogu.org/contestnew/show/11805?tdsourcetag=s_pcqq_aiomsg 题解: 没人过的题我就没看 t2: 考虑每个点是朋友 ...
- Codeforces Beta Round #22 (Div. 2 Only)
Codeforces Beta Round #22 (Div. 2 Only) http://codeforces.com/contest/22 A 水题 #include<bits/stdc+ ...
- Codeforces Beta Round #16 (Div. 2 Only)
Codeforces Beta Round #16 (Div. 2 Only) http://codeforces.com/contest/16 A 水题 #include<bits/stdc+ ...
- Codeforces Beta Round #12 (Div 2 Only)
Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...
- Codeforces Beta Round #57 (Div. 2)
Codeforces Beta Round #57 (Div. 2) http://codeforces.com/contest/61 A #include<bits/stdc++.h> ...
随机推荐
- PHP和MYSQL的编码问题
http://blog.csdn.net/martinkro/article/details/5352474 1 MYSQL中的字符集概念 Mysql的字符集里有两个概念,一个是"Char ...
- Oracle抓取表结构的语句
oracle --------------------------------------- SELECT case when t.COLUMN_ID=1 then t.table_name en ...
- DataTable.ImportRow()与DataTable.Rows.Add()的区别
今天写代码的时候用到ImportRow()向DataTable中添加记录,代码如下: DataTable dt = datatable;DataRow dr = dt.NewRow();dr[&quo ...
- java新手笔记8 包
1.main函数 public class MainParam { //考察main 方法的参数 args //运行时可以传入参数 参数类型 String public static void mai ...
- Druid 简单介绍
官方网址:http://code.alibabatech.com/wiki/display/Druid/Home 1.什么是Druid Druid首先是一个数据库连接池.Druid是目前最好的数据库连 ...
- Codevs 4560 NOIP2015 D2T2 子串
> 4560 NOIP2015 D2T2 子串 时间限制: 1 s 空间限制: 128000 KB 题目等级:黄金 Gold 题目描述 Description 有两个仅包含小写英文字母的字符串A ...
- .net开发人员等级
.net 开发人员的瓶颈和职业发展 现在社会比前几年浮躁了,越来越多的人抱怨薪水低,高薪工作不好找; 诚然这有CPI的压力,可是也有很多人没有认清自己的职业发展. 很多.net程序员个各种纠结,想拿高 ...
- MongoDB笔记(五)深入学习
系列一:http://www.cnblogs.com/huangxincheng/category/355399.html系列二:http://www.cnblogs.com/lipan/catego ...
- Linux Shell脚本之自动修改IP
作为一名Linux SA,日常运维中很多地方都会用到脚本,而服务器的ip一般采用静态ip或者MAC绑定,当然后者比较操作起来相对繁琐,而前者我们可以设置主机名.ip信息.网关等配置.修改成特定的主机名 ...
- PL/SQL学习(三)游标
原文参考:http://plsql-tutorial.com/ 两种类型: 隐式: 执行INSERT.UPDATE.DELETE 或者只返回一条结果的SELECT语句时默认创建 ...