AOAPC:Chapter1Example1 (UVa 11292)

本文展示了一段使用C++解决特定问题的程序代码。该程序通过读取输入数据并进行排序来解决一个关于资源分配的问题。具体而言,程序接收两个整数n和m作为输入,分别代表待处理的数组大小,并进一步读取这些数组的内容,然后对其进行排序以找出最优的配对方案。
#include "bits/stdc++.h"
using namespace std;

int main(int argc, char const *argv[]) {
  int n, m;
  while (scanf("%d%d", &n, &m), n || m) {
    int dir[20050] = { 0 };
    int abl[20050] = { 0 };
    for (size_t i = 0; i < n; ++i)
      scanf("%d", &dir[i]);
    for (size_t i = 0; i < m; ++i)
      scanf("%d", &abl[i]);
    sort(dir, dir + n);
    sort(abl, abl + m);
    int cost = 0, OKdra = 0;
    for (size_t i = 0; i < m && OKdra < n; ++i)
      if (dir[OKdra] <= abl[i]) { cost += abl[i]; OKdra +=1; }
    if (OKdra < n) puts ("Loowater is doomed!");
    else printf("%d\n", cost);
  }
  return 0;
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值