linyiweiblog

这道题像个水题啊,可是在我做的这个OJ上就十几人做出来……

题目来自:http://218.5.5.242:9018/JudgeOnline/problem.php?id=2084

题目描述

渔民抓住了n个金枪鱼,通过某个app卖给一家日本公司。这个app根据每只鱼的情况,给出两个值p1和p2。如果差值小等于x,那么更高的价格被采纳,如果差值确实大于x,那么app给出一个值p3,作为最终的采纳价格。写一个程序,根据给定的每只鱼的价格(有时是2个,有时是3个),给出抓住的鱼的总价格。

样例输入

5
2
3 4
2 1
5 3
4 4
4 2

样例输出

19

作者分析:这道题主要就是看如何输入p3,其它难度不大。
#include <bits/stdc++.h>
using namespace std;

int main(){
    int ans = 0,n,x,p1,p2,p3;
    cin >> n >> x;
    for (int i = 1;i <= n;i++){
        cin >> p1 >> p2;
        if (max(p1,p2) - min(p1,p2) > x){
            cin >> p3;
            ans += p3;
        }
        else{
            ans += max(p1,p2);
        }
    }
    cout << ans;
}

分类:

C++

技术点:

相关文章: