bzoj1307: 玩具
来源:互联网 发布:c 串口编程实例 编辑:程序博客网 时间:2024/06/09 17:01
好像数据很弱……
但我还是写了个较正常的乱搞解法?
考虑到这联续k个必定为1……k排列才能更新答案
我们先找到所有1的位置,然后在一个1到左右两个1的整个区间里扫描判重统计,具体参照代码
大概就是O(nlogn)的时间复杂度了
#include<iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<string>#include<map>#include<algorithm>#include<queue>using namespace std;int n;int a[1000005],b[1000005];int e[1000005];queue<int>que;priority_queue<int>Q;int cnt=0,ans=0,tot=0;int main(){ int i,j,k,t,l; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",&a[i]); if(a[i]==1){cnt++;b[cnt]=i;} } b[cnt+1]=n+1; for(i=1;i<=cnt;i++){ if(b[i+1]-1-b[i-1]>ans){ for(j=b[i+1]-1;j>b[i-1];j--){ if(e[a[j]]==0){ Q.push(a[j]); que.push(a[j]); e[a[j]]=1; tot++; } else{ while(que.front()!=a[j]){ while(!e[Q.top()])Q.pop(); k=Q.top(); if(k==tot)ans=max(k,ans); t=que.front(); e[t]=0;tot--;que.pop(); } } } if(tot!=0){ if(e[1]==1)if(Q.top()==tot)ans=max(ans,Q.top()); while(!que.empty()){t=que.front();e[t]=0;tot--;que.pop();} while(!Q.empty())Q.pop(); } } } printf("%d",ans); return 0;}
0 0
- bzoj1307: 玩具
- 【bzoj1318/bzoj1307】【玩具】【max】
- bzoj1307玩具/1318[Spoj744] Longest Permutation
- 我不是玩具
- 新玩具
- 小玩具
- 玩具机器人
- 网络玩具
- 玩具装箱
- 玩具宏
- 1307: 玩具
- 玩具工厂
- 玩具工厂
- zstu4273 玩具
- 4273: 玩具
- 儿童玩具,办公室玩具,居室玩具
- [东方宽频]玩具设计师的另类玩具
- 收集一些小玩具
- vue自定义指令
- poj1080
- day39_spring之struts2运行详解
- 南阳理工ACM 题目216 A problem is easy
- unit13文档
- bzoj1307: 玩具
- 不用加减乘除做加法
- 【ESP8266】NONOS SDK开发, smartconfig/AirKiss与flash读写
- 最大差值
- Codeforces 628 C. Bear and String Distance【贪心】
- 147. Insertion Sort List 题解
- ZOJ
- kylin——安装完成后不能进入web界面
- 单链表操作