跳到正文

题解

P17760 题解

_STD__约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年10月24日
收录
2026年10月24日
更新
2026年11月13日
篇幅
约 2 分钟
题目
P17760

版本

  1. v1当前

P17760 「奶龙OI」Round 3 - 生存大师

解法说明本题解使用贪心解题

题意梗概

两种镐,石镐只能挖石头,铁镐能挖石头和钻石,每挖一个掉一耐久,只能按顺序挖,求最多挖几个方块。

预处理分析

显然根据贪心,尽可能让铁镐挖到更多钻石,所以在石镐可用时,让石镐挖石头。

正式解题

注意:多测要在数据全输入完再跳出 实现如下

AC code
C++
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int t;
int a,b,n;
int cnt,flag;
void solve(){
    flag = 1;
    cnt = 0;
    cin >> n >> a >> b;
    for(int i = 1;i <= n;i++){
        int t;
        cin >> t;
        if(!a&&!b) flag = 0;
        if(t == 1 && flag ){
            if(a){
                cnt++; a--;
            }
            else if(b){
                cnt++; b--;
            }
        }
        if(t == 2 && flag){
            if(b){
                 cnt++; b--;
            }
            else{
                flag = 0;
            }
        }
    }
    cout<<cnt<<"\n";
}
int main(){
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}```
原文