///'C++///'//u5e76//u4e14//u4e0d//u4f7f//u7528///'VECTOR///'//u5934//u6587//u4ef6//u5b8c//u6210//uff1a//u5c0f//u53c2//u662f//u4e00//u540d//u8d44//u6599//u751f//u6d3b//u73a9//u5bb6//uff0c//u4ed6//u60f3//u8981//u5728//u6e38//u620f//u4e2d//u63d0//u9ad8//u81ea//u5df1//u7684//u89d2//u8272//u7b49//u7ea7//uff0c//u4e3a//u4e86//u8fbe//u5230//u8fd9//u4e2a//u76ee//u7684//uff0c//u5c0f//u53c2//u9700//u8981//u4e0d//u65ad//u7684//u6253//u602a//u5347//u7ea7//uff0c//u800c//u6253//u602a//u9700//u8981//u6d88//u8017//u4e00//u5b9a//u7684//u9b42//u529b//uff0c//u6e38//u620f//u4e2d//u4e5f//u6709//u4e00//u4e9b//u4e0d//u540c//u7684//u5668//u5177//u80fd//u591f//u6062//u590d//u9b42//u529b//uff0c//u5668//u5177//u4e00//u5171//u6709//u201ck//u201d//u7c7b//uff0c//u6bcf//u7c7b//u5668//u5177//u90fd//u9700//u8981//u4f7f//u7528//u4e0a//uff08//u5982//u679c//u6709//u7684//u8bdd//uff09//uff0c//u4f46//u6bcf//u4e2a//u5668//u5177//u90fd//u6709//u4e00//u4e2a//u6700//u5927//u7684//u6d88//u8017//u4e0a//u9650//uff0c//u6bd4//u5982//u9b42//u6cd5//u77f3//u6700//u591a//u4f7f//u7528//u201c1//u201d//u4e2a//uff0c//u9b42//u6cd5//u836f//u6db2//u6700//u591a//u4f7f//u7528//u201c2//u201d//u4e2a//u3002//u5f53//u7136//u5668//u5177//u4e5f//u6709//u4f7f//u7528//u4e0a//u9650//uff0c//u5c0f//u53c2//u60f3//u8981//u77e5//u9053//u5728//u6bcf//u79cd//u5668//u5177//u90fd//u4f7f//u7528//u7684//u60c5//u51b5//u4e0b//u80fd//u591f//u6062//u590d//u7684//u6700//u5927//u9b42//u529b//u503c//u662f//u591a//u5c11//uff1f//n//n//u8f93//u5165//u63cf//u8ff0//n//n//u7b2c//u4e00//u884c//u5305//u542b//u201c3//u201d//u4e2a//u6b63//u6574//u6570//u201cn//u201d//uff0c//u201cm//u201d//uff0c//u201ck//u201d//u3002//u8868//u793a//u5c0f//u53c2//u6700//u591a//u53ea//u80fd//u4f7f//u7528//u201cm//u201d//u4e2a//u5668//u5177//uff0c//u540c//u65f6//u6709//u201cn//u201d//u4e2a//u5668//u5177//u7ed9//u5c0f//u53c2//u9009//u62e9//uff0c//u800c//u8fd9//u201cn//u201d//u4e2a//u5668//u5177//u5206//u522b//u5c5e//u4e8e//u201ck//u201d//u7c7b//u3002//n//n//u7b2c//u4e8c//u884c//u5305//u542b//u201ck//u201d//u4e2a//u4e0d//u8d85//u8fc7//u201c10//u201d//u7684//u6b63//u6574//u6570//uff0c//u8868//u793a//u53ef//u4ee5//u4f7f//u7528//u201c1//u201d//u5230//u201ck//u201d//u7c7b//u5668//u5177//u7684//u6700//u5927//u6570//u91cf//u3002//n//n//u7ee7//u7eed//u201cn//u201d//u884c//u6bcf//u884c//u5305//u542b//u201c2//u201d//u4e2a//u6b63//u6574//u6570//uff0c//u5206//u522b//u8868//u793a//u8be5//u5668//u5177//u7684//u9b42//u529b//u503c//u201cai//u201d//u548c//u5c5e//u52a0//u7c7b//u522b//u201cbi//u201d//u3002//n//n//u8f93//u51fa//u63cf//u8ff0//n//n//u5171//u4e00//u884c//uff0c//u4e00//u4e2a//u6570//u5b57//u5c31//u662f//u53ef//u4ee5//u6062//u590d//u7684//u6700//u5927//u9b42//u529b//u503c//u3002//n//n//u7528//u4f8b//u8f93//u5165//u201c1//u201d//n//n//u201c6//u201c//u201c6//u201d//u201c3//u201d//n//u201c3//u201d//u201c3//u201d//u201c2//u201d//n//u201c15//u201d//u201c1//u201d//n//u201c15//u201d//u201c2//u201d//n//u201c10//u201d//u201c2//u201d//n//u201c15//u201d//u201c2//u201d//n//u201c10//u201d//u201c2//u201d//n//u201c5//u201d//u201c3//u201d//n//u7528//u4f8b//u8f93//u51fa//u201c1//u201d//n//n//u201c60//u201d//n//u63d0//u793a//n//n//u201cn//u201d//u201c//u201c200//u201d//uff0c//u201cm//u201d//u201c//u201c100//u201d//uff0c//u201ck//u201d//u201c//u201c100//u201d//uff1b//u201cai//u201d//u201c//u201c100//u201d//uff0c//u201cbi//u201d//u201c//u201ck//u201d//u3002//n//u5185//u5bb9//uff1a//n//u89e3//u9898//u60f3//u8def//uff1a//n//u9996//u5148//uff0c//u6211//u4eec//u9700//u8981//u6309//u7167//u5668//u5177//u7684//u7c7b//u522b//u8fdb//u884c//u5206//u7c7b//uff0c//u5c06//u540c//u4e00//u7c7b//u522b//u7684//u5668//u5177//u653e//u5230//u4e00//u8d77//u3002//n//u7136//u540e//uff0c//u5bf9//u4e8e//u6bcf//u4e00//u7c7b//u5668//u5177//uff0c//u6211//u4eec//u9700//u8981//u6839//u636e//u5668//u5177//u7684//u6700//u5927//u4f7f//u7528//u6570//u91cf//u548c//u6d88//u8017//u4e0a//u9650//uff0c//u786e//u5b9a//u80fd//u591f//u4f7f//u7528//u7684//u5668//u5177//u4e2a//u6570//u3002//u5177//u4f53//u800c//u8a00//uff0c//u5982//u679c//u5668//u5177//u7684//u6700//u5927//u4f7f//u7528//u6570//u91cf//u5c0f//u4e8e//u7b49//u4e8e//u5668//u5177//u7684//u6d88//u8017//u4e0a//u9650//uff0c//u5219//u53ef//u4ee5//u5168//u90e8//u4f7f//u7528//uff1b//u5982//u679c//u5668//u5177//u7684//u6700//u5927//u4f7f//u7528//u6570//u91cf//u5927//u4e8e//u5668//u5177//u7684//u6d88//u8017//u4e0a//u9650//uff0c//u5219//u53ea//u80fd//u4f7f//u7528//u5668//u5177//u7684//u6d88//u8017//u4e0a//u9650//u4e2a//u5668//u5177//u3002//n//u7ee7//u7eed//u4e0b//u6765//uff0c//u5bf9//u4e8e//u6bcf//u4e00//u7c7b//u5668//u5177//uff0c//u6211//u4eec//u9700//u8981//u6839//u636e//u5668//u5177//u7684//u9b42//u529b//u503c//u548c//u4f7f//u7528//u7684//u6570//u91cf//uff0c//u8ba1//u7b97//u8be5//u7c7b//u5668//u5177//u80fd//u591f//u6062//u590d//u7684//u6700//u5927//u9b42//u529b//u503c//u3002//n//u6700//u540e//uff0c//u5c06//u6bcf//u4e00//u7c7b//u5668//u5177//u80fd//u591f//u6062//u590d//u7684//u6700//u5927//u9b42//u529b//u503c//u76f8//u52a0//uff0c//u5f97//u5230//u6700//u7ec8//u7684//u7ed3//u679c//u3002//n//n//u5177//u4f53//u5b9e//u73b0//u6b65//u9aa4//u5982//u4e0b//uff1a//n//u201c1//u201d//u3002//u5b9a//u4e49//u4e00//u4e2a//u7ed3//u6784//u4f53//u201cItem//u201d//uff0c//u8868//u793a//u5668//u5177//uff0c//u5305//u62ec//u9b42//u529b//u503c//u548c//u5c5e//u52a0//u7c7b//u522b//u3002//n//u201c2//u201d//u3002//u5b9a//u4e49//u4e00//u4e2a//u6570//u7ec4//u201citems//u201d//uff0c//u7528//u4e8e//u5b58//u50a8//u6240//u6709//u7684//u5668//u5177//u3002//n//u201c3//u201d//u3002//u8f93//u5165//u201cn//u201d//uff0c//u201cm//u201d//uff0c//u201ck//u201d//uff0c//u5206//u522b//u8868//u793a//u5668//u5177//u6570//u91cf//uff0c//u6700//u591a//u4f7f//u7528//u5668//u5177//u6570//u91cf//uff0c//u5668//u5177//u7c7b//u522b//u6570//u91cf//u3002//n//u201c4//u201d//u3002//u8f93//u5165//u6bcf//u4e00//u7c7b//u5668//u5177//u7684//u6700//u5927//u4f7f//u7528//u6570//u91cf//uff0c//u5c06//u5176//u4fdd//u5b58//u5728//u6570//u7ec4//u201cmax/_count//u201d//u4e2d//u3002//n//u201c5//u201d//u3002//u8f93//u5165//u201cn//u201d//u884c//uff0c//u6bcf//u884c//u8f93//u5165//u5668//u5177//u7684//u9b42//u529b//u503c//u548c//u5c5e//u52a0//u7c7b//u522b//uff0c//u5c06//u5176//u4fdd//u5b58//u5728//u6570//u7ec4//u201citems//u201d//u4e2d//u3002//n//u201c6//u201d//u3002//u5bf9//u6570//u7ec4//u201citems//u201d//u6309//u7167//u5668//u5177//u7684//u7c7b//u522b//u8fdb//u884c//u5206//u7c7b//uff0c//u5c06//u540c//u4e00//u7c7b//u522b//u7684//u5668//u5177//u653e//u5230//u4e00//u8d77//u3002//n//u201c7//u201d//u3002//u5b9a//u4e49//u4e00//u4e2a//u53d8//u91cf//u201ctotal/_magic//u201d//uff0c//u8868//u793a//u80fd//u591f//u6062//u590d//u7684//u6700//u5927//u9b42//u529b//u503c//uff0c//u521d//u59cb//u5316//u4e3a//u201c0//u201d//u3002//n//u201c8//u201d//u3002//u5bf9//u4e8e//u6bcf//u4e00//u7c7b//u5668//u5177//uff0c//u6839//u636e//u5668//u5177//u7684//u6700//u5927//u4f7f//u7528//u6570//u91cf//u548c//u6d88//u8017//u4e0a//u9650//uff0c//u786e//u5b9a//u80fd//u591f//u4f7f//u7528//u7684//u5668//u5177//u4e2a//u6570//uff0c//u5e76//u6839//u636e//u5668//u5177//u7684//u9b42//u529b//u503c//u548c//u4f7f//u7528//u7684//u6570//u91cf//uff0c//u8ba1//u7b97//u8be5//u7c7b//u5668//u5177//u80fd//u591f//u6062//u590d//u7684//u6700//u5927//u9b42//u529b//u503c//uff0c//u5c06//u5176//u7d2f//u52a0//u5230//u201ctotal/_magic//u201d//u4e2d//u3002//n//u201c9//u201d//u3002//u8f93//u51fa//u201ctotal/_magic//u201d//uff0c//u8868//u793a//u6700//u5927//u80fd//u591f//u6062//u590d//u7684//u9b42//u529b//u503c//u3002//n//n//u4ee3//u7801//u5b9e//u73b0//u5982//u4e0b//uff1a//n```cpp#include #include using namespace std;struct Item { int magic; int category;};bool cmp(Item a, Item b) { return a.category < b.category;}int main() { int n, m, k; cin >> n >> m >> k; int max_count[k]; for (int i = 0; i < k; i++) { cin >> max_count[i]; } Item items[n]; for (int i = 0; i < n; i++) { cin >> items[i].magic >> items[i].category; } sort(items, items + n, cmp); int total_magic = 0; int count[k] = {0}; for (int i = 0; i < n; i++) { int category = items[i].category; int magic = items[i].magic; if (count[category - 1] < max_count[category - 1]) { total_magic += magic; count[category - 1]++; m--; } else if (m > 0) { total_magic += magic; m--; } } cout << total_magic << endl; return 0

C++ 不使用 VECTOR 头文件完成:最大魔力恢复问题

原文地址: https://www.cveoy.top/t/topic/pTQQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录