zoukankan      html  css  js  c++  java
  • 最长的斜坡。。。。

    未名湖是圆形而且如果中间有中断就算是从新开始。。
    Weiming Lake, also named “Un-named Lake”, is the most famous scenic spot in Peking University. It is located in the north of the campus and is surrounded by walking paths, small gardens, and old red buildings with typical Chinese curly roofs. The lake was once the royal garden in Qing Dynasty. Boya tower stands on a little hill beside the lake. The lake and the tower form a distinctive landscape and a symbol of Peking University.

    Weiming Lake is a very good place for studying, reading, skating in the winter, and of course, jogging. More and more students and teachers run or walk around Weiming Lake every day and show how many paces they have covered in the mobile app WeChat Sports to get “Zans” (applauses).

    ACMer X also enjoys jogging around Weiming Lake. His watch can measure and record an altitude value every meter. After a round of running, X collected the altitude data around the lake. Now he wants to find out the longest slope around the lake.

    Input

    There are no more than 20 test cases.

    Each case has two lines.

    The first line is an integer N (2 <= N <= 100) meaning that the length of the road around the lake is N meters.

    The second line contains N integers a1,a2…aN, (0<= a1,a2…aN <= 100) indicating N altitude sample values around the lake. The samples are given in clockwise order, and the distance between two adjacent samples is one meter. Of course the distance between a1 and aN is also one meter.

    The input ends by a line of 0.

    Output

    For each test case, print the length of the longest slope in meters. A slope is a part of the road around the lake, and it must keep going up or going down. If there are no slope, print 0.

    Sample Input

    4

    1 1 1 1

    8

    5 1 2 3 4 5 6 2

    6

    5 4 3 2 1 2

    10

    1 0 2 3 2 2 3 4 3 2

    0

    Sample Output

    0

    5

    4

    4

    //看见英文题还是有种想死的感觉。
    //借鉴大神的代码。。

    #include<stdio.h>
    #include<algorithm>
    #include<string.h>
    using namespace std;
    int a[1000];
    int b[1000];
    int c[1000];
    int main()
    {
        int n;
        while(~scanf("%d",&n)&&n)
        {
            memset(b,0,sizeof(b));
            memset(b,0,sizeof(b));
            for(int i=0;i<n;i++)
            {
                scanf("%d",&a[i]);
            }
            for(int i=n;i<2*n;i++)
            {
                a[i]=a[i-n];
            }
            int x=0,y1=0,y2=0;
            for(int i=1;i<2*n;i++)
            {
                if(a[i]>a[i-1])
                    x=max(x,++y1);
                else
                    y1=0;
                if(a[i]<a[i-1])
                    x=max(x,++y2);
                else
                    y2=0;
    
            }
            printf("%d
    ",x);
        }
    }
    
  • 相关阅读:
    5.对象创建型模式-原型PROTOTYPE
    4.对象创建型模式-工厂方法
    3.对象创建型模式-生成器
    一个小应用的dbcp和c3p0配置实例
    利用 java.lang.Runtime.addShutdownHook() 钩子程序,保证java程序安全退出
    初探maven插件机制
    【转载】Git push时重复输入用户名密码的问题
    【转载】 ERROR 1045 (28000): Access denied for user root@localhost (using password: NO)
    【转载】[Java]读取文件方法大全
    【原创】iframe与父页面之间,变量、方法互相调用
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053376.html
Copyright © 2011-2022 走看看