zoukankan      html  css  js  c++  java
  • P1478 陶陶摘苹果(升级版)

    https://www.luogu.com.cn/problem/P1478

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int n, s, a, b;
     4 struct apple{      //结构体定义苹果的高度和摘苹果所用的力气 
     5     int x, y;
     6 };
     7 apple t[5005];     //用于存放各个苹果 
     8 bool cmp(apple a, apple b){    //按照摘苹果所用力气大小从小到大排序 
     9     return a.y < b.y;
    10 }
    11 int ans;
    12 int main()
    13 {
    14     cin>>n>>s;
    15     cin>>a>>b;
    16     for(int i=0; i<n; i++)
    17         cin>>t[i].x>>t[i].y;
    18         
    19     sort(t, t+n, cmp);     //按照摘苹果所用力气大小从小到大排序
    20 
    21     for(int i=0; i<n; i++){
    22         if(s>=t[i].y && a+b>=t[i].x){     //力气数大于当前苹果所用力气  且  高度大于等于苹果高度 
    23             ans++;
    24             //cout<<ans<<":"<<t[i].x<<" "<<t[i].y<<endl;     //测试所摘苹果 
    25             s-=t[i].y;    
    26         }
    27         if(s<0)break;
    28     }
    29     cout<<ans;
    30     return 0;
    31 }
  • 相关阅读:
    swift
    swift
    ios
    Swift
    swift
    swift
    /var/log/cron
    Django 数据传递
    HTML 属性
    HTML 元素
  • 原文地址:https://www.cnblogs.com/tflsnoi/p/13365388.html
Copyright © 2011-2022 走看看