RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0627

Roundabout Rounding

Silver II 실버 II
난이도
2s
시간 제한
256MB
메모리 제한
1
맞았습니다!!
2
제출 수
50.0%
정답률
레이팅

의견: 0

설명

Bessie the cow is back in school! She has started doing her math homework in
which she is tasked to round positive integers to powers of \(10\).

To round a positive integer \(a\) to the nearest \(10^b\), where \(b\) is a positive
integer, Bessie first locates the \(b\)'th digit from the right. Let \(x\) denote
this digit.

If \(x \geq 5\), Bessie adds \(10^b\) to \(a\).

Then, Bessie sets all the digits including and to the right of the \(b\)'th digit
from the right to be \(0\).

For instance, if Bessie wanted to round \(456\) to the nearest \(10^2\) (hundred),
Bessie would first locate the \(2\)nd digit from the right which is \(5\). This
means \(x = 5\). Then since \(x \geq 5\), Bessie adds \(100\) to \(a\). Finally, Bessie
sets all the digits in \(a\) to the right of and including the \(2\)nd digit from
the right to be \(0\), resulting in \(500\).

However, if Bessie were to round \(446\) to the nearest \(10^2\), she would end up
with \(400\).

After looking at Bessie's homework, Elsie thinks she has invented a new type of
rounding: chain rounding. To chain round to the nearest \(10^b\), Elsie will first
round to the nearest \(10^1\), then the nearest \(10^2\), and so on until the
nearest \(10^b\).

Bessie thinks Elsie is wrong, but is too busy with math homework to confirm her
suspicions. She tasks you to count how many integers \(x\) at least \(2\) and at
most \(N\) (\(1 \leq N \leq 10^{9}\)) exist such that rounding \(x\) to the nearest
\(10^P\) is different than chain rounding to the nearest \(10^P\), where \(P\) is the
smallest integer such that \(10^P \geq x\).

Problem credits: Weiming Zhou

제약

SCORING

  • Inputs 2-4: \(N\le 10^3\)
  • Inputs 5-7: \(N\le 10^6\)
  • Inputs 8-13: No additional constraints.

Problem credits: Weiming Zhou

입력 형식

You have to answer multiple test cases.

The first line of input contains a single integer \(T\) (\(1 \leq T \leq 10^5\))
denoting the number of test cases. \(T\) test cases follow.

The first and only line of input in every test case contains a single integer
\(N\). All \(N\) within the same input file are guaranteed to be distinct.

출력 형식

Output \(T\) lines, the \(i\)'th line containing the answer to the \(i\)'th test case.
Each line should be an integer denoting how many integers at least \(2\) and at
most \(N\) exist that are different when using the two rounding methods.

예제 1
입력
4
1
100
4567
3366
출력
0
5
183
60
설명

Consider the second test case in the sample. \(48\) should be counted because \(48\)
chain rounded to the nearest \(10^2\) is \(100\) (\(48\to 50\to 100\)), but \(48\)
rounded to the nearest \(10^2\) is
\(0\).

In the third test case, two integers counted are \(48\) and \(480\). \(48\) chain
rounds to \(100\) instead of to \(0\) and \(480\) chain rounds to \(1000\) instead of
\(0\). However, \(67\) is not counted since it chain rounds to \(100\) which is \(67\)
rounded to the nearest \(10^2\).

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > December > Bronze

태그

평가 및 의견

Roundabout Rounding

개요
출제자 난이도 Silver II 실버 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Roundabout Rounding

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8