当前位置:网站首页>【暑期每日一题】洛谷 P7760 [COCI2016-2017#5] Tuna
【暑期每日一题】洛谷 P7760 [COCI2016-2017#5] Tuna
2022-07-29 07:08:00 【AC_Dragon】
题目链接:P7760 [COCI2016-2017#5] Tuna - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
题目描述
渔夫在昨晚捕到 N 条金枪鱼。他准备将这些鱼卖给一个平台。
对于每一条鱼,平台会给出两个估测值 P1,P2。如果这两个值之差不超过 X,则取较大的值作为该条鱼的价值;否则如果差超过 X,则取另一个值 P3。
现在给定 N 条鱼的值(可能会有 2 个或 3 个),求所有鱼的总价值。
输入格式
第一行,一个整数 N,表示金枪鱼的数量。
第二行,一个整数 X。
接下来的若干行分为 N 个部分用来表示每条鱼的信息。每部分的格式为下列二者之一:
- 该部分仅有唯一一行,该行包含两个整数 P1,P2。
- 该部分共有两行,第一行包含两个整数 P1,P2,第二行包含一个整数 P3。
输出格式
输出所有鱼的总价值。
样例 #1
样例输入 #1
5
2
3 4
2 1
5 3
4 4
4 2样例输出 #1
19样例 #2
样例输入 #2
4
2
3 5
2 8
4
6 5
6 3
7样例输出 #2
22样例 #3
样例输入 #3
3
10
20 50
30
20 40
50
70 20
10样例输出 #3
90提示
【样例 2 解释】
渔夫捕到了 4 条金枪鱼,而 X 的值为 2:

故价值总和为 5+4+6+7 = 22。
【数据规模与约定】
对于 100% 的数据,1 <= N <= 20,1 <= X <= 10,1 <= P1,P2,P3 <= 100。
【提示与说明】
题目译自 COCI 2016-2017 CONTEST #5 T1 Tuna。
本题分值按 COCI 原题设置,满分 50。
AC code:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
cin>>n;
int x;
cin>>x;
int sum=0;
while(n--)
{
int p1,p2;
cin>>p1>>p2;
if(abs(p1-p2)>x)
{
int p3;
cin>>p3;
sum+=p3;
}
else
{
sum+=max(p1,p2);
}
}
cout<<sum;
return 0;
} 边栏推荐
- 1 - background project construction
- QT基础第二天(2)qt基础部件:按钮类,布局类,输出类,输入类,容器等个别举例
- QT basic day 2 (2) QT basic components: button class, layout class, output class, input class, container and other individual examples
- mysql 单表最多能存多少数据?
- leetcode力扣经典问题——4.寻找两个正序数组的中位数
- 2-统一返回类DTO对象
- NPM install reports an error NPM err could not resolve dependency NPM err peer
- 【暑期每日一题】洛谷 P4414 [COCI2006-2007#2] ABC
- Introduction to logback appender
- Gin service exit
猜你喜欢

09 bloom filter

Ethernet interface introduction

MySQL uses the client and select methods to view the summary of blob type fields

leetcode力扣经典问题——4.寻找两个正序数组的中位数

在线问题反馈模块实战(十七):实现excel模板在线下载功能

Variables and encryption in ansible

JS chicken laying eggs and egg laying chickens. Who appeared earlier, object or function? Is function an instance of function?

Paper reading (62):pointer networks

Job 7.28 file IO and standard IO

亚马逊云助手小程序来啦!
随机推荐
js中break与continue和return关键字
QT topic: basic components (button class, layout class, output class, input class, container class)
【暑期每日一题】洛谷 P4414 [COCI2006-2007#2] ABC
Introduction to logback filter
QT连接两个qslite数据库报错QSqlQuery::exec: database not open
Scala 高阶(十):Scala中的异常处理
电子元器件贸易企业如何借助ERP系统,解决仓库管理难题?
logback 中FileAppender具有什么功能呢?
logback filter过滤器简介说明
1-后台项目搭建
Interface test actual project 03: execute test cases
Leetcode buckle classic problem -- 4. Find the median of two positively ordered arrays
【OpenGL】着色器(Shader)的使用
MySQL - multi table query
LevelFilter简介说明
vue-router路由缓存
2-统一返回类DTO对象
3-global exception handling
MySQL advanced (Advanced) SQL statement (I)
Excel file reading and writing (creation and parsing)