CCP-CSP认证考试 201909-1 小明种苹果 c/c++题解

本文深入探讨了一个使用C++解决复杂算法问题的竞赛编程案例。通过对代码的详细解析,展示了如何利用多种C++标准库进行高效的数据处理和算法实现。文章通过一个具体的题目,讲解了如何读取输入数据,进行数据预处理,以及如何设计算法来解决问题。同时,文中还涉及了变量声明、循环结构、条件判断等基本语法,以及如何使用标准输入输出流进行数据交互。
摘要由CSDN通过智能技术生成

题目描述

在这里插入图片描述
在这里插入图片描述

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <list>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <iterator>
using namespace std;

typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll  INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double E = exp(1.0);
const int MOD = 1e9+7;
const int MAX = 1e3+5;
int n,m;
int a[MAX];

int main()
{
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    */

    while(cin >> n >> m)
    {
        int maxNum,maxId; maxNum = 0;// 最多疏果个数及其编号
        int sum = 0;// 最后剩下的苹果个数
        int tmp1;
        for(int i = 1; i <= n; i++)
        {
            cin >> tmp1;
            sum += tmp1;
            int tmp2;
            int tmpMax = 0;
            for(int j = 1; j <= m; j++)
            {
                cin >> tmp2;
                tmpMax += abs(tmp2);
            }
            sum -= tmpMax;
            if(tmpMax > maxNum)
            {
                maxNum = tmpMax; maxId = i;
            }
        }
        cout << sum << " " << maxId << " " << maxNum << endl;
    }

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值