BZOJ1293: [SCOI2009]生日礼物
来源:互联网 发布:ubuntu rar压缩文件夹 编辑:程序博客网 时间:2024/04/29 11:35
题目链接
我用的二分+单调队列变式。。不会用堆,还写得丑,,跑到3000+ms。。
【代码】
#include <cstdio>#include <iostream>#include <queue>#include <vector>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#define N 1000005#define M 200005#define INF 0x7fffffffusing namespace std;typedef long long ll;typedef pair<ll,ll> pa;int read(){ int x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();} return x*f;}int n,m,cnt,ans;int num[65],Q[N];class node{ public: int pos,t;}e[N];bool cmp(node a,node b){ return a.pos<b.pos;}bool Judge(int mid){ for(int i=1;i<=n;i++) num[i]=0; int head=1,tail=0,sum=0; for(int i=1;i<=n;i++) { Q[++tail]=i; num[e[i].t]++; if(num[e[i].t]==1) sum++; while(head<=tail&&e[Q[tail]].pos>e[Q[head]].pos+mid) { num[e[Q[head]].t]--; if(!num[e[Q[head]].t]) sum--; head++; } if(sum==m) return true; } return false;}void B_Search(){ int l=0,r=e[n].pos-e[1].pos; while(l<=r) { int mid=l+r>>1; if(Judge(mid)) ans=mid,r=mid-1; else l=mid+1; } printf("%d\n",ans);}int main(){ n=read(),m=read(); for(int i=1;i<=m;i++) { int x=read(); while(x--) { e[++cnt].pos=read(); e[cnt].t=i; } } sort(e+1,e+1+n,cmp); B_Search(); return 0;}
0 0
- bzoj1293: [SCOI2009]生日礼物 贪心
- [BZOJ1293]SCOI2009生日礼物|贪心
- bzoj1293【SCOI2009】生日礼物
- BZOJ1293: [SCOI2009]生日礼物
- 【bzoj1293】【SCOI2009】【生日礼物】
- BZOJ1293: [SCOI2009]生日礼物
- bzoj1293: [SCOI2009]生日礼物
- bzoj1293: [SCOI2009]生日礼物
- [BZOJ1293][SCOI2009]生日礼物-堆
- BZOJ1293 [SCOI2009]生日礼物
- BZOJ1293 [SCOI2009]生日礼物 【队列】
- 【BZOJ1293】【SCOI2009】生日礼物 单调性
- [bzoj1293][SCOI2009]生日礼物(莫队)
- bzoj1293: [SCOI2009]生日礼物(堆)
- bzoj1293: [SCOI2009]生日礼物 单调队列
- BZOJ1293(SCOI2009)[生日礼物]--维护区间
- [BZOJ1293][SCOI2009]生日礼物(单调队列)
- [bzoj1293][SCOI2009]生日礼物 单调队列优化dp
- C++递归方法计算n阶行列式
- linux下如何用C进行录音,录成.WAV格式,或者其他格式
- SQL Server2008函数大全
- 微信小程序入门二: 条件、遍历、网络请求、获取本地图片
- web项目的整体架构(spring)相关配置文件说明
- BZOJ1293: [SCOI2009]生日礼物
- 编程语言
- 散列(hash)
- qt - How can I convert a QImage of format RGB32 to OpenCV::mat? - Stack Overflow
- Fiddler工具条常用功能
- Spring 整合 MongoDB
- java,支行期间将字符串放入常量池
- 围棋AI连胜人类50场,是时候认真思考如何应对人工智能了
- servlet+重定向+转发+数据传递