zoukankan      html  css  js  c++  java
  • ACM 第二天

    A - Mishka and Contest

    Mishka started participating in a programming contest. There are n problems in the contest. Mishka's problem-solving skill is equal to k

    .

    Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.

    Mishka cannot solve a problem with difficulty greater than k

    . When Mishka solves the problem, it disappears from the list, so the length of the list decreases by 1

    . Mishka stops when he is unable to solve any problem from any end of the list.

    How many problems can Mishka solve?

    Input

    The first line of input contains two integers n

    and k (1n,k100

    ) — the number of problems in the contest and Mishka's problem-solving skill.

    The second line of input contains n

    integers a1,a2,,an (1ai100), where ai is the difficulty of the i

    -th problem. The problems are given in order from the leftmost to the rightmost in the list.

    Output

    Print one integer — the maximum number of problems Mishka can solve.

    Examples
    Input
    8 4
    4 2 3 1 5 1 6 4
    Output
    5
    Input
    5 2
    3 1 2 1 3
    Output
    0
    Input
    5 100
    12 34 55 43 21
    Output
    5
    Note

    In the first example, Mishka can solve problems in the following order: [4,2,3,1,5,1,6,4][2,3,1,5,1,6,4][2,3,1,5,1,6][3,1,5,1,6][1,5,1,6][5,1,6]

    , so the number of solved problems will be equal to 5

    .

    In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than k

    .

    In the third example, Mishka's solving skill is so amazing that he can solve all the problems.

     1 #include<stdio.h>
     2 int main()
     3 {
     4     int n,k;
     5     int a[102];
     6     int s=0;
     7     int t=0;
     8     scanf("%d %d",&n,&k);
     9     for(int i=0;i<n;i++)
    10     {
    11         scanf("%d",&a[i]);
    12     }
    13     for(int i=0;i<n;i++)
    14     {
    15 
    16         if(a[i]<=k)
    17         {
    18             s++;
    19             t++;
    20         }
    21         else
    22             break;
    23     }
    24     for(int i=n-1;i>=t;i--)
    25     {
    26         if(a[i]<=k)
    27         {
    28             s++;
    29         }
    30         else
    31             break;
    32     }
    33     printf("%d
    ",s);
    34     return 0;
    35 }
    雪儿言
  • 相关阅读:
    学PHP应注意的问题与知识点
    php 的生命周期
    Pyhton中汉字的使用方法(转)
    院外培训:GIS数据处理与建模高级培训班学习心得体会 来自
    绕人的python汉字问题
    arcmap导出或者打印时插入的图片和对象绘制失败
    【百度地图API】如何获取行政区域的边界? (转)
    VS2010不能编译.Net3.5项目的解决方法(转)
    ArcGIS中Python汉字使用说明(转)
    ArcGIS10联网无法启动问题解决
  • 原文地址:https://www.cnblogs.com/weixq351/p/9359362.html
Copyright © 2011-2022 走看看