当前位置:网站首页>【小码匠自习室】[NOI Online 2020-2 入门组] 未了:可恶的精度会让你焦头烂额
【小码匠自习室】[NOI Online 2020-2 入门组] 未了:可恶的精度会让你焦头烂额
2022-08-08 13:53:00 【小码匠】
碎碎念
- 当你妄想将几个除不尽后又四舍五入过的小数加在一起打算充当分配律用时,那么,这将是一个悲伤的故事,因为可恶的精度会让你焦头烂额……
标签
- 贪心、二分查找
题目地址
- [NOI Online #2 入门组] 未了
- https://www.luogu.com.cn/problem/P6473
题目描述
输入格式
第一行三个整数 n,L,v 分别表示魔法的种类数,山坡的长度,Sisyphus 的速度。
第二行 n 个整数。第 i 个整数 a_i 表示第 i 个魔法作用的位置。(1<i<n)
第三行一个整数 q 表示宙斯的询问个数。
接下来 q 行每行一个整数,第 i 行的整数 t_i 表示宙斯的第 i 个询问。(1<i<n)
输出格式
输出 q 行,每行恰好一个整数,第 i行的整数对应第 i 个询问的答案。(1≤i≤q)
如果宙斯无论如何都不能使 Sisyphus 使用的年数大于 t_i ,请输出 −1。
输入输出样例
输入 #1
3 6 3
3 5 1
4
1
3
4
5
输出 #1
0
1
2
-1
说明/提示
题解
小码匠题解一
- 一次AC
void coder_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, l;
double v;
cin >> n >> l >> v;
vector<double> a(n);
vector<double> b(n);
for(int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end(), greater<int>());
b[0] = a[0] / v;
for(int i = 1 ; i < n; ++i) {
a[i] += a[i - 1];
b[i] = a[i] / v;
}
int q, t;
cin >> q;
double T = l / v;
int cnt;
for(int i = 0; i < q; ++i) {
cin >> t;
if(T > t) {
cout << 0 << endl;
} else {
cnt = upper_bound(b.begin(), b.end(), t - T) - b.begin();
if (cnt >= n) {
cout << -1 << endl;
} else {
cout << cnt + 1 << endl;
}
}
}
}
边栏推荐
- 更改C盘用户目录下的用户名(亲测有效)
- textarea 禁止拖拽
- 【Personal Summary】2022.8.7 Week End
- 删库不易,跑路更难
- mysql 查询一个字段为特定值,并且另一个字段的值出现两次的记录?
- Implement a customized pin code input control
- Knowledge points and written test questions related to shift operations, bit operations, and logical operations
- Flink1.15源码阅读——StreamGraph流图
- Code Casual Recording Notes_Dynamic Programming_322 Change Exchange
- 华为云弹性云服务器ECS使用【华为云至简致远】
猜你喜欢
年初离职,学习半年源码,终于拿到了蚂蚁Offer,分享面试过程
机器学习+深度学习笔记(持续更新~)
从零开始,如何拥有自己的博客网站【华为云至简致远】
Review: What is the pre-approval of autumn recruitment?What is an ordinary autumn move?It's all recruitment, why do you need to set these two recruitment time periods?
【Redis】位图以及位图的使用场景(统计在线人数和用户在线状态)
win32&mfc————win32菜单栏&库
QWebAssembly中文适配
客户案例 | 提高银行信用卡客户贡献率
window停掉指定端口的进程
Experience Sharing | Systematic Design and Development of Business Cache
随机推荐
Implementation of FIR filter based on FPGA (1) - using fir1 function design
兔起鹘落全端涵盖,Go lang1.18入门精炼教程,由白丁入鸿儒,全平台(Sublime 4)Go lang开发环境搭建EP00
PHP中使用XML-RPC构造Web Service简单入门
【Personal Summary】2022.8.7 Week End
客户案例 | 提高银行信用卡客户贡献率
剑指 Offer 66. 构建乘积数组
Time to update your tech arsenal in 2020: Asgi vs Wsgi (FastAPI vs Flask)
sample function—R language
Verilog语法基础HDL Bits训练 09
HackTheBox | Horizontall
flutter 身兼数职的getx —— 简介
String转成double等类型注意非空判断
优刻得“失速”:营收转降,定向增发股东浮亏超三成
设计一个跨平台的即时通讯系统(采用华为云ECS服务器作为服务端 )【华为云至简致远】
【Redis】redis安装与客户端redis-cli的使用(批量操作)
Tensorflow and Keras for machine learning, deep learning
KD-SCFNet:通过知识蒸馏实现更准确、更高效的显着目标检测(ECCV2022)
a += 1 += 1为什么是错的?
Pretraining Weekly Issue 56: Long Text Understanding, Instant Question Answering, Mask Self-Supervision
[Redis] Bitmap and usage scenarios of bitmap (statistics of online people and user online status)