codeforces#FF(div2) DZY Loves Sequences,

來源:互聯網
上載者:User

codeforces#FF(div2) DZY Loves Sequences,

n個數,可以任意改變其中一個數,求最長的上升子區間長度

思路:記錄一個from[i]表示從位置i的數開始最長的上升區間長度

    記錄一個to[i]表示到位置i的數所能達到的最長上升區間長度

枚舉要改變的數的位置i,此時能達到的長度為to[i - 1] + from[i + 1] + 1,取最大值


//#pragma comment(linker, "/STACK:102400000,102400000")//HEAD#include <cstdio>#include <cstring>#include <vector>#include <iostream>#include <algorithm>#include <queue>#include <string>#include <set>#include <stack>#include <map>#include <cmath>#include <cstdlib>using namespace std;//LOOP#define FE(i, a, b) for(int i = (a); i <= (b); ++i)#define FED(i, b, a) for(int i = (b); i>= (a); --i)#define REP(i, N) for(int i = 0; i < (N); ++i)#define CLR(A,value) memset(A,value,sizeof(A))//STL#define PB push_back//INPUT#define RI(n) scanf("%d", &n)#define RII(n, m) scanf("%d%d", &n, &m)#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)#define RS(s) scanf("%s", s)typedef long long LL;const int INF = 0x3f3f3f3f;const int MAXN = 1010;#define FF(i, a, b) for(int i = (a); i < (b); ++i)#define FD(i, b, a) for(int i = (b) - 1; i >= (a); --i)#define CPY(a, b) memcpy(a, b, sizeof(a))#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)#define EQ(a, b) (fabs((a) - (b)) <= 1e-10)#define ALL(c) (c).begin(), (c).end()#define SZ(V) (int)V.size()#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)#define WI(n) printf("%d\n", n)#define WS(s) printf("%s\n", s)typedef vector <int> VI;typedef unsigned long long ULL;const double eps = 1e-10;const LL MOD = 1e9 + 7;int a[100010];int to[100010], from[100010];int main(){    //freopen("0.txt", "r", stdin);    int n;    while (~RI(n))    {        FE(i, 1, n) RI(a[i]), to[i] = from[i] = 1;        FE(i, 2, n)            if (a[i] > a[i - 1])                to[i] = to[i - 1] + 1;        FED(i, n - 1, 1)            if (a[i + 1] > a[i])                from[i] = from[i + 1] + 1;//        FE(i, 1, n)//            cout << to[i] <<' ';;cout << endl;//        FE(i, 1, n)//            cout << from[i] <<' ' ; cout << endl;        int ans = 1;        if (n > 1)            ans = max(from[2] + 1, to[n - 1] + 1);        FE(i, 2, n - 1)        {            if (a[i + 1] - a[i - 1] >= 2)            {                if (to[i - 1] + from[i + 1] + 1 > ans)                {                    ans = to[i - 1] + from[i + 1] + 1;//                    cout << i <<endl;                }            }            else            {                ans = max(ans, to[i - 1] +1);                ans = max(ans, from[i + 1] + 1);            }        }        cout << ans << endl;    }    return 0;}



codeforces問題: codeforces比賽怎攻擊別人?

對某一題,首先你自己要先過TEST。然後回到比賽的PROBLEM列表,把這題後面的鎖鎖上(鎖上了就不能再提交了,所以沒把握就別鎖了),然後到ROOM裡面,你就可以看別人代碼了,下面有HACK按鈕,點一下,輸入你覺得他錯的範例。
 
codeforces在比賽結束後怎看題目的測試資料

先進相應的比賽,然後點standing 雙擊裡面過了的人相應的分數 點AC就是AC代碼
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.