Zhongshan Jizhong Day1-- popularity

Morning together, I could feel a driving rain. Across thousands of miles, came to the front of Jizhong, he decided in a dauntless heroism stepped into the examination room.

God face four questions. Then, I succeeded over five hurdles, A lost two questions! ! !


T1:APPLE

   Wexley recently discovered an ancient game screen. The game screen is divided into n columns. In the bottom of the screen, there is a wide basket (m <n) m columns. In the course of the game, Wexley can move around the basket, Wexley operation is very sharp, moving is instantaneous, but the basket must always on the screen. From the top of the screen falling apples, each apple from the top of a column in the n-th column falling, vertical drop to the bottom of the screen. Each apple on an apple always fall in the end when the end began to fall. Wexley want by moving the basket to catch all the apples. At first, the extreme left of the screen basket.
        Wexley determined to catch all the apples on the shortest distance required to move. 

Thinking: This simple little question, set up left and right, and then judge, mobile, savings can be.

See Code:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,k,a[21],l=1,r,ans;
int main()
{
    //freopen("apple.in","r",stdin);
    //freopen("apple.out","w",stdout);
    scanf("%d%d%d",&n,&m,&k);
    r=m;
    for(int i=1;i<=k;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]>r)
        {
            while(a[i]>r)
            {
                ans++;
                l++;
                r++;
            }
        }
        while(a[i]<l)
        {
            ans++;
            l--;
            r--;
        }
    }
    printf("%d",ans);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/qing1/p/11281984.html