zoukankan      html  css  js  c++  java
  • Sequence II

    6990: Sequence II

    时间限制: 3 Sec  内存限制: 128 MB
    提交: 206  解决: 23
    [提交][状态][讨论版][命题人:admin]

    题目描述

    We define an element ai in a sequence "good", if and only if there exists a j(1≤ j < i) such that aj < ai.
    Given a permutation p of integers from 1 to n. Remove an element from the permutation such that the number of "good" elements is maximized.
     

    输入

    The input consists of several test cases. The first line of the input gives the number of test cases, T(1≤ T≤ 10^3).
    For each test case, the first line contains an integer n(1≤ n≤ 10^6), representing the length of the given permutation.
    The second line contains n integers p1,p2,cdots,pn(1≤ pi≤ n), representing  the given permutation p.
    It’s guaranteed that Σn≤ 2× 10^7.
     

    输出

    For each test case, output one integer in a single line, representing the element that should be deleted. If there are several answers, output the minimal one.

    样例输入

    2
    1
    1
    5
    5 1 2 3 4
    

    样例输出

    1
    5
    骚的输入操作,用scanf()居然超时!

    #include <bits/stdc++.h>
    using namespace std;
    int scan()
    {
    int res=0;
    char ch;
    ch=getchar();
    if(ch>='0' && ch<='9')
    {
    res=ch-'0';
    }
    while((ch=getchar())>='0' && ch<='9')
    {
    res=res*10+ch-'0';
    }
    return res;
    }
    void out(int a)
    {
    if(a>9)
    {
    out(a/10);
    }
    putchar(a%10+'0');
    }
    int b[1000100];
    int a[1000100];
    int main()
    {
    int t,n,rr,zxz,minn,minnn;
    t=scan();
    while(t--)
    {
    memset(b,0,sizeof(b));
    n=scan();
    if(n==1)
    {
    a[0]=scan();
    out(a[0]);
    putchar(' ');
    }
    if(n==2)
    {
    a[0]=scan();
    a[1]=scan();
    out(min(a[0],a[1]));
    putchar(' ');
    }
    if(n>=3)
    {
    for(int i=0; i<=n-1; i++)
    {
    a[i]=scan();
    if(i==1)
    {
    minnn=min(a[0],a[1]);
    minn=max(a[0],a[1]);
    if(a[0]<a[1])
    {
    b[a[0]]++;
    b[a[1]]++;
    }
    }
    else if(i>1)
    {
    if(a[i]<minnn)
    {
    minn=minnn;
    minnn=a[i];
    }
    else if(a[i]>minnn && a[i]<minn)
    {
    b[minnn]++;
    b[a[i]]++;
    minn=a[i];
    }
    else if(a[i]>minn)
    {
    b[a[i]]++;
    }
    }
    }
    rr=1e9+7;
    zxz=1e9+7;
    for(int i=0;i<=n-1;i++)
    {
    if(b[a[i]]<zxz)
    {
    zxz=b[a[i]];
    rr=a[i];
    }
    else if(b[a[i]]==zxz && a[i]<rr)
    {
    rr=a[i];
    }
    }
    out(rr);
    putchar(' ');
    }
    }
    return 0;
    }

  • 相关阅读:
    第二个月课堂009python之总结(002)
    python的接口自动化测试+ddt数据驱动(*****)
    python题(002)
    selenium问题归纳一:多个句柄索引会乱的问题
    多测师讲解python讲解__xlwt__模块(拓展莫模块002)
    多测师python面试题__整理和答案(001)高级讲师肖sir
    第二个月课堂012讲解 _ Unittest框架(上)_高级讲师肖sir
    多测师讲解课堂11课__selenium__错归纳_高级讲师肖sir
    ActionChains定位元素
    css使用方法
  • 原文地址:https://www.cnblogs.com/lglh/p/9079116.html
Copyright © 2011-2022 走看看