本文分享的必刷题目是从蓝桥云课、洛谷、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 11到N 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)(1≤i≤N)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