• 【CF1029B】Creating the Contest(贪心)


    题意:

    n<=2e5

    思路:可以证明答案一定是极长的一段中取最大值

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<string>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<map>
     8 #include<set>
     9 #include<queue>
    10 #include<vector>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned int uint;
    14 typedef unsigned long long ull;
    15 typedef pair<int,int> PII;
    16 typedef vector<int> VI;
    17 #define fi first
    18 #define se second 
    19 #define MP make_pair
    20 #define N   5100000
    21 #define MOD 1e9+7 
    22 #define eps 1e-8 
    23 #define pi acos(-1)
    24 
    25 int a[210000],dp[210000],ans,t,w;
    26 
    27             
    28 
    29 int read()
    30 { 
    31    int v=0,f=1;
    32    char c=getchar();
    33    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
    34    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
    35    return v*f;
    36 }
    37 
    38 void swap(int &x,int &y)
    39 {
    40     int t=x;x=y;y=t;
    41 }
    42 
    43 
    44         
    45 int main()
    46 {
    47 //    freopen("1.in","r",stdin);
    48 //    freopen("1.out","w",stdout);
    49     int n;
    50     scanf("%d",&n);
    51     for(int i=1;i<=n;i++) a[i]=read();
    52 
    53     ans=1;
    54     w=1;
    55     t=0;
    56     dp[1]=1;
    57     for(int i=2;i<=n;i++) 
    58     {
    59         dp[i]=1;
    60         while(w+1<=n&&a[w]*2<a[i]) w++;
    61         while(w+1<i&&w+1<=n&&a[w+1]*2>=a[i]) w++;
    62         if(w<i) dp[i]=max(dp[i],dp[w]+1);
    63         ans=max(ans,dp[i]);
    64         //printf("%d %d %d
    ",i,w,dp[i]);
    65     }
    66     printf("%d",ans); 
    67     return 0;
    68 }
  • 相关阅读:
    java生成UUID通用唯一识别码 (Universally Unique Identifier)
    使用ToolRunner运行Hadoop程序基本原理分析
    Hadoop入门经典:WordCount
    Hadoop配置文件
    【Nutch2.2.1基础教程之3】Nutch2.2.1配置文件
    8大排序算法图文讲解
    动态字典树_前缀相互查找(HDU_1671)
    DP_基本DP+排序(HDU_1421)
    斯特灵公式
    七种 qsort 排序方法
  • 原文地址:https://www.cnblogs.com/myx12345/p/9844368.html
Copyright © 2020-2023  润新知