news 2026/4/24 23:43:27

题解:AtCoder AT_awc0003_a Product Quality Evaluation

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
题解:AtCoder AT_awc0003_a Product Quality Evaluation

本文分享的必刷题目是从蓝桥云课洛谷AcWing等知名刷题平台精心挑选而来,并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构,旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。

欢迎大家订阅我的专栏:算法题解:C++与Python实现!

附上汇总贴:算法竞赛备考冲刺必刷题(C++) | 汇总


【题目来源】

AtCoder:A - Product Quality Evaluation

【题目描述】

Takahashi is in charge of quality control at a factory. This factory manufacturesN NNtypes of products, each numbered from1 11toN NN.
高桥负责一家工厂的质量控制工作。这家工厂生产N NN种产品,每种产品编号从1 11N NN

Each product has two metrics: a “quality index” and a “production quantity.” The quality index of producti iiisA i A_iAi, and its daily production quantity isB i B_iBiunits. A higher quality index indicates that defective items are more likely to occur.
每种产品有两个指标:“质量指数"和"生产数量”。产品i ii的质量指数为A i A_iAi,其日生产数量为B i B_iBi单位。质量指数越高,表明次品出现的可能性越大。

Takahashi decided to calculate a “risk score” for each product. The risk score of producti iiis defined as the product of the quality indexA i A_iAiand the production quantityB i B_iBi, namelyA i × B i A_i \times B_iAi×Bi. A higher risk score means that more attention is required for that product.
高桥决定为每种产品计算一个"风险分数"。产品i ii的风险分数定义为质量指数A i A_iAi与生产数量B i B_iBi的乘积,即A i × B i A_i × B_iAi×Bi。风险分数越高,意味着该产品需要更多关注。

Takahashi believes that products with a risk score ofK KKor higher need to be prioritized for improvement. Find the number of products whose risk score isK KKor higher.
高桥认为,风险分数为K KK或更高的产品需要优先进行改进。求风险分数为K KK或更高的产品数量。

【输入】

N NNK KK
A 1 A_1A1B 1 B_1B1
A 2 A_2A2B 2 B_2B2
⋮ \vdots
A N A_NANB N B_NBN

  • The first line contains an integerN NNrepresenting the number of product types and an integerK KKrepresenting the risk score threshold, separated by a space.
  • From the 2nd line to the( N + 1 ) (N+1)(N+1)-th line, information about each product is given.
  • The( i + 1 ) (i+1)(i+1)-th line( 1 ≤ i ≤ N ) (1 \leq i \leq N)(1iN)contains the quality indexA i A_iAiand the production quantityB i B_iBiof producti ii, separated by a space.

【输出】

Output the number of products whose risk score isK KKor higher, in a single line.

【输入样例】

3 100 10 5 20 10 5 30

【输出样例】

2

【解题思路】

【算法标签】

#模拟#

【代码详解】

#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongintn,k,ans;// n: 商品数量,k: 目标金额,ans: 计数signedmain(){cin>>n>>k;// 读入商品数量和目标金额for(inti=1;i<=n;i++){inta,b;// a: 单价,b: 数量cin>>a>>b;// 读入单价和数量if(a*b>=k)// 如果总价大于等于目标金额k{ans++;// 计数器加1}}cout<<ans<<endl;// 输出满足条件的商品数量return0;}

【运行结果】

3 100 10 5 20 10 5 30 2
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/24 23:42:52

Minecraft电影级画面终极指南:Photon Shader光影包完全教程

Minecraft电影级画面终极指南&#xff1a;Photon Shader光影包完全教程 【免费下载链接】photon A gameplay-focused shader pack for Minecraft 项目地址: https://gitcode.com/gh_mirrors/photon3/photon 想要将你的Minecraft世界从简单的方块游戏变成电影级的视觉盛宴…

作者头像 李华
网站建设 2026/4/24 23:42:21

Hadoop大数据时代的底座和基石

引言 说起大数据&#xff0c;很多人脑海中第一个浮现的就是Hadoop。但Hadoop到底是个啥&#xff1f;它是一个框架、一个生态&#xff0c;还是一种理念&#xff1f;这篇文章&#xff0c;带你一次性把Hadoop彻底搞清楚。 文章目录引言一、Hadoop是什么&#xff1f;二、Hadoop的诞…

作者头像 李华
网站建设 2026/4/24 23:34:07

用 Excel 逐步展示 MLP 的前向传播、反向传播和参数更新

用 Excel 逐步展示 MLP 的前向传播、反向传播和参数更新 配套 Excel 文件&#xff1a;MLP计算过程.xlsx 这篇文章配合 Excel 阅读&#xff0c;不写成纯理论推导。 为避免公式在不同博客平台、Windows 编辑器或 Markdown 预览器中出现乱码&#xff0c;本文的公式全部使用 ASCII …

作者头像 李华