NC225362. Digital Speedometer
描述
输入描述
The first line of input contains , the falling threshold. The second line of input contains , the rising threshold. Thespeed sensor reports in increments of mph. The thresholds are always set halfway between speed increments.All remaining lines until end-of-file are successive decimal speeds, , in miles per hour, one speed per line. The thirdline of input, which is the first measured speed, will always be . There are at most observed speeds in input.
输出描述
Output is the list of speeds, one speed per line, smoothed to integer values appropriate to and .
示例1
输入:
0.25 0.75 0 2.0 5.7 5.8 5.7 5.2 5.7 0.8 0.2
输出:
0 2 5 6 6 5 5 1 1
说明:
C++(clang++ 11.0.1) 解法, 执行用时: 6ms, 内存消耗: 416K, 提交时间: 2023-07-11 19:10:08
#include <bits/stdc++.h> using namespace std; double tf, tr, s, ans; int main() { cin >> tf >> tr; while(cin>>s) { int i = s, j = i+1; if(s == 0) ans = 0; else if(s < 1) ans = 1; else if(i <= s && s < i+tf) ans = i; else if(i+tr < s && s <= j) ans = j; else if(ans < i+tr) ans = i; else ans = j; cout << ans << endl; } }