Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
nlogn算法,有点短 我写错了么?用时好多#include<iostream> using namespace std; int i, j, n, k, p, a[40000], stack[40000]; int search(int s, int e) { while(s != e) { if(stack[(s+e)/2] > a[j]) e = (s+e)/2; else s = (s+e)/2+1; } return s; } int main() { cin>>k; for(i = 1; i <= k; i++) { cin>>n; for(j = 1; j <= n; j++) cin>>a[j]; p = 1; stack[1] = a[1]; for(j = 2; j <= n; j++) { if(a[j] > stack[p]) { p++; stack[p] = a[j]; } else stack[search(1, p)] = a[j]; } cout<<p<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator