当前位置:网站首页>【暑期每日一题】洛谷 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;
}
边栏推荐
- QT topic: basic components (button class, layout class, output class, input class, container class)
- Summary of OCR optical character recognition methods
- 0 9 布隆过滤器(Bloom Filter)
- JS 鸡生蛋与蛋生鸡问题,Object与Function究竟谁出现的更早?Function算不算Function的实例?
- JS day 4 process control (if statement and switch statement)
- Docker最新超详细教程——Docker创建运行MySQL并挂载
- do end用法的妙处
- mysql 单表最多能存多少数据?
- 7-2 calculate the area and perimeter of a regular pentagon (25 points)
- vue-router路由缓存
猜你喜欢
我,28岁,测试员,10月无情被辞:想给还在学测试 的人提个醒......
MySQL uses the client and select methods to view the summary of blob type fields
Ansible中的变量及加密
【WPF】通过动态/静态资源实现语言切换
2022-07-28: what is the output of the following go language code? A:AA; B:AB; C:BA; D:BB。 package main import ( “fmt“ ) func main() { f
WPF interface layout must know basis
1 - background project construction
How to establish EDI connection with Scania in Scania?
在线问题反馈模块实战(十七):实现excel模板在线下载功能
Scala higher order (10): exception handling in Scala
随机推荐
jdbc入门
关于大龄读博的几点回答?
Meta configuration item of route
Latest 10 billion quantitative private placement list
力扣(LeetCode)209. 长度最小的子数组(2022.07.28)
2022-07-28: what is the output of the following go language code? A:AA; B:AB; C:BA; D:BB。 package main import ( “fmt“ ) func main() { f
QT topic: basic components (button class, layout class, output class, input class, container class)
微服务远程调用
【暑期每日一题】洛谷 P4414 [COCI2006-2007#2] ABC
PAT甲级 1146 拓扑顺序
js中break与continue和return关键字
2-unified return class dto object
Levelfilter introduction
CMOS芯片制造全工艺流程
Operator3-设计一个operator
Introduction to logback appender
彻底搞懂kubernetes调度框架与插件
利用C语言巧妙实现棋类游戏——三子棋
如何使用gs_expansion扩展节点
logback日志级别简介说明