zoukankan      html  css  js  c++  java
  • POJ1877,3903 LIS

      1877题目链接:http://poj.org/problem?id=1887

      3903题目链接:http://poj.org/problem?id=3903

      数据大,线性优化,O(n*logn)。

    1877:

     1 //STATUS:C++_AC_16MS_172KB
     2 #include <functional>
     3 #include <algorithm>
     4 #include <iostream>
     5 //#include <ext/rope>
     6 #include <fstream>
     7 #include <sstream>
     8 #include <iomanip>
     9 #include <numeric>
    10 #include <cstring>
    11 #include <cassert>
    12 #include <cstdio>
    13 #include <string>
    14 #include <vector>
    15 #include <bitset>
    16 #include <queue>
    17 #include <stack>
    18 #include <cmath>
    19 #include <ctime>
    20 #include <list>
    21 #include <set>
    22 #include <map>
    23 using namespace std;
    24 //define
    25 #define pii pair<int,int>
    26 #define mem(a,b) memset(a,b,sizeof(a))
    27 #define lson l,mid,rt<<1
    28 #define rson mid+1,r,rt<<1|1
    29 #define PI acos(-1.0)
    30 //typedef
    31 typedef __int64 LL;
    32 typedef unsigned __int64 ULL;
    33 //const
    34 const int N=800010;
    35 const int INF=0x3f3f3f3f;
    36 const int MOD=100000,STA=8000010;
    37 const LL LNF=1LL<<60;
    38 const double EPS=1e-8;
    39 const double OO=1e15;
    40 const int dx[4]={-1,0,1,0};
    41 const int dy[4]={0,1,0,-1};
    42 //Daily Use ...
    43 inline int sign(double x){return (x>EPS)-(x<-EPS);}
    44 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
    45 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
    46 template<class T> inline T Min(T a,T b){return a<b?a:b;}
    47 template<class T> inline T Max(T a,T b){return a>b?a:b;}
    48 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
    49 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
    50 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
    51 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
    52 //End
    53 
    54 int num,f[N];
    55 int T,n;
    56 
    57 int binary(int l,int r,int tar)
    58 {
    59     int mid;
    60     while(l<r){
    61         mid=(l+r)>>1;
    62         if(f[mid]>=tar)l=mid+1;
    63         else r=mid;
    64     }
    65     return l;
    66 }
    67 
    68 int main()
    69 {
    70  //   freopen("in.txt","r",stdin);
    71     int i,j,l,r,k,ca=1;
    72     while(1){
    73         scanf("%d",&num);
    74         if(num==-1)break;
    75         l=1;r=2;
    76         f[1]=num;
    77         while(1){
    78             scanf("%d",&num);
    79             if(num==-1)break;
    80             k=binary(l,r,num);
    81             f[k]=num;
    82             r=Max(r,k+1);
    83         }
    84 
    85         printf("Test #%d:\n",ca++);
    86         printf("  maximum possible interceptions: %d\n\n",r-1);
    87     }
    88     return 0;
    89 }
    View Code

    3903:

     1 //STATUS:C++_AC_63MS_756KB
     2 #include <functional>
     3 #include <algorithm>
     4 #include <iostream>
     5 //#include <ext/rope>
     6 #include <fstream>
     7 #include <sstream>
     8 #include <iomanip>
     9 #include <numeric>
    10 #include <cstring>
    11 #include <cassert>
    12 #include <cstdio>
    13 #include <string>
    14 #include <vector>
    15 #include <bitset>
    16 #include <queue>
    17 #include <stack>
    18 #include <cmath>
    19 #include <ctime>
    20 #include <list>
    21 #include <set>
    22 #include <map>
    23 using namespace std;
    24 //define
    25 #define pii pair<int,int>
    26 #define mem(a,b) memset(a,b,sizeof(a))
    27 #define lson l,mid,rt<<1
    28 #define rson mid+1,r,rt<<1|1
    29 #define PI acos(-1.0)
    30 //typedef
    31 typedef __int64 LL;
    32 typedef unsigned __int64 ULL;
    33 //const
    34 const int N=100010;
    35 const int INF=0x3f3f3f3f;
    36 const int MOD=100000,STA=8000010;
    37 const LL LNF=1LL<<60;
    38 const double EPS=1e-8;
    39 const double OO=1e15;
    40 const int dx[4]={-1,0,1,0};
    41 const int dy[4]={0,1,0,-1};
    42 //Daily Use ...
    43 inline int sign(double x){return (x>EPS)-(x<-EPS);}
    44 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
    45 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
    46 template<class T> inline T Min(T a,T b){return a<b?a:b;}
    47 template<class T> inline T Max(T a,T b){return a>b?a:b;}
    48 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
    49 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
    50 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
    51 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
    52 //End
    53 
    54 int num[N],f[N];
    55 int T,n;
    56 
    57 int binary(int l,int r,int tar)
    58 {
    59     int mid;
    60     while(l<r){
    61         mid=(l+r)>>1;
    62         if(f[mid]<tar)l=mid+1;
    63         else r=mid;
    64     }
    65     return l;
    66 }
    67 
    68 int main()
    69 {
    70  //   freopen("in.txt","r",stdin);
    71     int i,j,l,r,k;
    72     while(~scanf("%d",&n))
    73     {
    74         for(i=0;i<n;i++){
    75             scanf("%d",&num[i]);
    76         }
    77 
    78         l=1;r=2;
    79         f[1]=INF;
    80         for(i=0;i<n;i++){
    81             k=binary(l,r,num[i]);
    82             f[k]=num[i];
    83             r=Max(r,k+1);
    84         }
    85 
    86         printf("%d\n",r-1);
    87     }
    88     return 0;
    89 }
    View Code
  • 相关阅读:
    fw:Hadoop、Pig、Hive、Storm、NOSQL 学习资源收集【Updating】
    【Azure 环境】用 PowerShell 调用 AAD Token, 以及调用Azure REST API(如资源组列表)
    【Azure 环境】使用Azure中的App Service部署Web应用,以Windows为主机系统是否可以启动防病毒,防恶意软件服务呢(Microsoft Antimalware)?
    【Azure 应用程序见解】通过无代码方式在App Service中启用Application Insights后,如何修改在Application Insights中显示的App Service实例名呢?
    【Azure API 管理】API Management service (APIM) 如何实现禁止外网访问
    【Azure 环境】Azure门户中 Metrics 图表的聚合指标每项具体代表什么意思呢?
    【Azure Redis 缓存】Redis导出数据文件变小 / 在新的Redis复原后数据大小压缩近一倍问题分析
    【Azure 事件中心】在Windows系统中使用 kafkaconsumergroups.bat 查看Event Hub中kafka的consumer groups信息
    RadToolTip (点击按钮,弹出ToolTip)
    Url传值,传入中文,读取时出现乱码的解决方案
  • 原文地址:https://www.cnblogs.com/zhsl/p/3089984.html
Copyright © 2011-2022 走看看