标签:img 分享 include enqueue div ios image can typedef
思路:要实现输出很简单,关键是时间的限制,当时提交了很多次,一直是超时,后来改用二分法,才交上去。
#include<stdio.h> #include<iostream> using namespace std; typedef struct { int *base; int font; int rear; } SqQueue; void InitQueue(SqQueue& L) { L.base=new int[100010]; L.font=0; L.rear=0; } void SqSearch(SqQueue& L, int m) { int r,f,mid; f=L.font; r=L.rear; while(f<r) { mid=(r-f)/2+f; if(L.base[mid]>m)r=mid; else if(L.base[mid]<m)f=mid+1; } L.base[r]=m; } void EnQueue(SqQueue& L,int m) { int length=L.rear-L.font; if(length==0) { L.base[0]=m; L.rear++; } else { if(m>L.base[L.rear-1]) { L.base[L.rear]=m; L.rear++; } else SqSearch(L,m); } } int main() { SqQueue L; InitQueue(L); int n,m; scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&m); EnQueue(L,m); } printf("%d",L.rear-L.font); return 0; }
标签:img 分享 include enqueue div ios image can typedef
原文地址:http://www.cnblogs.com/suppercobweb/p/7724359.html