Luo Tao Tao Gu 1478 upgraded version of Apple picking

Title Description

It is a year when the autumn, Tao Tao home apple trees bear the fruit of n. Tao Tao ran to pick apples, this time she had a centimeter of a chair. When he hands out of reach, he will stand on a chair to try again.

The popularity of the group and NOIp2005 the first question is different: to move stool before Tao Tao, the effort is only a s. Of course, every time I have to pick apples with some effort. Tao Tao to pick up to want to know how many apples before s <0.

Now known apple reaches a height xi n the ground, the height of the chair a, the maximum length of Tao Tao hand straight b, Tao Tao remaining strength s, Tao Tao needs to pick an apple effort yi, seeking to pick up to Tao Tao how many apple.

Input and output formats

Input formats:

Line 1: count two apples n, strength s.

Line 2: the height of the chair two numbers a, the maximum length straight hand Toto b.

The third line to the line 3 + n-1: the number of two per row height apples xi, apple picking effort required yi.

Output formats:

Only one integer representing the number of apples to pick up to Tao Tao.

Sample input and output

Input Sample # 1:
8 15
20 130
120 3
150 2
110 7
180 1
50 8
200 0
140 3
120 2
Output Sample # 1:
4

Explanation

All data: n <= 5000 a <= 50 b <= 200 s <= 1000

      xi<=280  yi<=100
我的代码
#include<iostream>
using namespace std;
int x[5001],y[5001],a,b,n,s,t=0;
bool used[5001];//标记该苹果是否被摘
int main()
{
    cin>>n>>s;
    cin>>a>>b;
    a=a+b;
    for(int i=1;i<=n;i++)
    {
        cin>>x[i];
        cin>>y[i];
        used[i]=0;
    }
    for(int i=1;i<=n;i++)
    if(x[i]>a) used[i]=1;//若摘不到,视为已摘
        int i=0;
        while(s>=0)
        {
           int j=10000,k=1;
           i=1;
           while(used[i]&&i<=n) i++; //若苹果被摘,下一个
           while(i<=n)
               {
                   if(j>y[i]&&!used[i])
               {
                   j=y[i];//j标记所用最小的力气
                   k=i;//k标记要摘的苹果
               }    
                   i++;
               }
            used[k]=1;//苹果已摘
            s-=j;//力气减少
            t++;//个数加一
        }
    cout<<t-1;//s小于零个数才加一,减去最后一个实际摘不到的
    return 0;
}
Published 29 original articles · won praise 3 · Views 3208

Guess you like

Origin blog.csdn.net/qq_38436175/article/details/73433611
Recommended