zoukankan      html  css  js  c++  java
  • codeforces #321 DIV2

    A题:

    链接:http://codeforces.com/contest/580/problem/A

    dp,最长连续不上升子序列

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<string>
     5 #include<cmath>
     6 #include<algorithm>
     7 using namespace std;
     8 const int maxn=100010;
     9 int a[maxn],dp[maxn];
    10 int main()
    11 {
    12     int n;
    13     while(cin>>n)
    14     {
    15         for(int i=0;i<n;i++)
    16             scanf("%d",&a[i]);
    17         memset(dp,0,sizeof(dp));
    18         dp[0]=1;
    19         for(int i=1;i<n;i++)
    20         {
    21             if(a[i-1]<=a[i])
    22                 dp[i]=dp[i-1]+1;
    23                 else
    24                     dp[i]=1;
    25         }
    26         int mx=0;
    27         for(int i=0;i<n;i++)
    28             if(dp[i]>mx)
    29             mx=dp[i];
    30         cout<<mx<<endl;
    31     }
    32     return 0;
    33 }
    View Code

    B题:

    链接:http://codeforces.com/contest/580/problem/B

    贪心,先按照m升序排序,然后找出符合条件且最大的

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<string>
     5 #include<cmath>
     6 #include<vector>
     7 #include<algorithm>
     8 using namespace std;
     9 const int maxn=100010;
    10 typedef struct
    11 {
    12     long long m,s;
    13 }point;
    14 point p[maxn];
    15 bool cmp(point a,point b)
    16 {
    17     return a.m<b.m;
    18 }
    19 int main()
    20 {
    21     long long n,d;
    22     while(cin>>n>>d)
    23     {
    24         for(int i=0;i<n;i++)
    25             cin>>p[i].m>>p[i].s;
    26         sort(p,p+n,cmp);
    27         long long ans=0;
    28         long long cnt=0;
    29         int j=0;
    30         for(int i=0;i<n;i++)
    31         {
    32             cnt+=p[i].s;
    33             while(p[i].m-p[j].m>=d)
    34             {
    35                 cnt-=p[j].s;
    36                 j++;
    37             }
    38             ans=max(ans,cnt);
    39         }
    40         cout<<ans<<endl;
    41     }
    42     return 0;
    43 }
    View Code

    C、D、E赛场上没有搞出来,抽时间来补上

  • 相关阅读:
    面向对象三大特性五大原则
    如何快速的浏览项目
    网页测速
    截取字符串
    iOS-tableView点击下拉菜单
    iOS_block内存分析
    iOS_ @property参数分析
    iOS-设计模式之Block
    iOS-设计模式之代理反向传值
    iOS-设计模式之通知
  • 原文地址:https://www.cnblogs.com/wolf940509/p/4837005.html
Copyright © 2011-2022 走看看