#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> using namespace std; const int maxn = 100000; //----------------------------- int a[maxn],lis[maxn]; int n,k; //----------------------------- void readfile() { n = 1; a[n]=k; int u; cin >> u; if (u==-1) return; while (u!=-1) { a[++n]=u; cin >> u; } return; } //----------------------------- int find(int i, int j, int x) { int l,r,m; l = i; r = j; do { m = (l+r)/2; if (lis[m]<x) r = m; else l = m; } while (r-l>1); if (lis[l]<x) return(l); else if (lis[r]<x) return(r); else return(-1); } //----------------------------- int solve() { int result = 1; memset(lis,0,sizeof(lis)); for (int i=1; i<=n; i++) { int pos = find(1,result,a[i]); if (pos==-1) lis[++result] = a[i]; else lis[pos] = a[i]; } return(result); } //----------------------------- int main() { int test=0; cin >> k; while (k!=-1) { test++; if (test>1) cout << endl; readfile(); printf("Test #%d:\n",test); cout << " maximum possible interceptions: "; cout << solve() << endl; cin >> k; } return 0; }
Sunday, August 17, 2014
uva : 231 - Testing the CATCHER
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment