首页 > 其他分享 >洛谷题单指南-排序-P2676 [USACO07DEC] Bookshelf B

洛谷题单指南-排序-P2676 [USACO07DEC] Bookshelf B

时间:2024-01-30 10:34:21浏览次数:24  
标签:P2676 int 洛谷题 Bookshelf 排序 USACO07DEC

原题链接:https://www.luogu.com.cn/problem/P2676

题意解读:要使能够到书架顶的牛数量最少,优先选高的牛即可,直到总身高超过书架高度,简单的排序+贪心,下面给出代码。

100分代码:

#include <bits/stdc++.h>
using namespace std;

const int N = 20005;

int h[N];
int n, b;

int main()
{
    cin >> n >> b;
    for(int i = 1; i <= n; i++) cin >> h[i];

    sort(h + 1, h + n + 1, greater<int>());

    int sum = 0, cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        sum += h[i];
        cnt++;
        if(sum >= b) break;
    }

    cout << cnt;
    
    return 0;
}

 

标签:P2676,int,洛谷题,Bookshelf,排序,USACO07DEC
From: https://www.cnblogs.com/jcwy/p/17996565

相关文章

  • 洛谷题单指南-排序-P1781 宇宙总统
    原题链接:https://www.luogu.com.cn/problem/P1781题意解读:题目思路非常简单,在n个投票数中选最大的,并记录其编号即可,由于投票数很大,无法直接用整形,需要通过string来进行数字比较。解题思路:本题的关键在于如何比较string数字的大小?在高精度减法时,需要判断两个数的大小,用大数减小......
  • 洛谷题解-[ABC286E] Souvenir
    https://www.luogu.com.cn/problem/AT_abc286_e题目描述NNN個の都市があり、いくつかの相異なる都市の間は一方通行の直行便によって移動することができます。どの直行便が存在するかはNNN個の長さNNNの文字列S1,S2,…,SNS_1,S_2,\ldots,S_NS1​,S2​,…,SN​......
  • 洛谷题解-[ABC325E] Our clients, please wait a moment
    https://www.luogu.com.cn/problem/AT_abc325_e题目描述ある国には都市がNNN個あります。あなたは、都市111にある営業所から000個以上の都市を経由して都市NNNにある訪問先へ移動しようとしています。移動手段は社用車と電車の222種類があります。都市......
  • 洛谷题单指南-排序-P1093 [NOIP2007 普及组] 奖学金
    原题链接:https://www.luogu.com.cn/problem/P1093题意解读:本题考察排序,根据题意,先按总分从大到小排,再按语文从大到小排,以上都相同则按学号从小到大排。100分代码:#include<bits/stdc++.h>usingnamespacestd;constintN=305;structstudent{intid;intyuw......
  • 洛谷题单指南-排序-P1059 [NOIP2006 普及组] 明明的随机数
    原题链接:https://www.luogu.com.cn/problem/P1059题意解读:此题主要做两件事:排序+去重,用计数排序即可解决,直接给出代码。100分代码:#include<bits/stdc++.h>usingnamespacestd;constintN=1005;inta[N];intn;intmain(){cin>>n;intx;intcnt......
  • 洛谷题解-[ARC001B] リモコン
    https://www.luogu.com.cn/problem/AT_arc001_2题目描述 输入格式无输出格式无题意翻译题目描述:高桥君要调整空调的设定温度。现在的设定温度是A度,而他想调到B度。空调遥控器按一次可以:上调或下调1度上调或下调5度上调或下调10度高桥君想求出从A调到B度的最小......
  • 洛谷题解-P1938 [USACO09NOV] Job Hunt S
    https://www.luogu.com.cn/problem/P1938题目描述Bessieisrunningoutofmoneyandissearchingforjobs.FarmerJohnknowsthisandwantsthecowstotravelaroundsohehasimposedarulethathiscowscanonlymakeD(1<=D<=1,000)dollarsinac......
  • 洛谷题解-P2888 [USACO07NOV] Cow Hurdles S (Floyd)
    https://www.luogu.com.cn/problem/P2888题目描述FarmerJohnwantsthecowstoprepareforthecountyjumpingcompetition,soBessieandthegangarepracticingjumpingoverhurdles.Theyaregettingtired,though,sotheywanttobeabletouseaslittleene......
  • 洛谷题解-P3003 [USACO10DEC] Apple Delivery S (dijkstra)
    题目描述Bessiehastwocrispredapplestodelivertotwoofherfriendsintheherd.Ofcourse,shetravelstheC(1<=C<=200,000)cowpathswhicharearrangedastheusualgraphwhichconnectsP(1<=P<=100,000)pasturesconvenientlynumb......
  • 洛谷题单指南-排序-P1923 【深基9.例4】求第 k 小的数
    原题链接:https://www.luogu.com.cn/problem/P1923题意解读:要最快的求第k小的数,O(n)的做法是利用快排的思想对数据进行划分第一步、取分界点x,通常设x=a[(l+r)/2]第二步、将小于x的挪到x左边,将大于x的挪到x右边第三步、比较,如果x左边的个数大于k,则继续递归处理左边,否则递......