[日記] 也寫了112資工系演算法hw2的Problem 4
2015年10月16日Fri. 早上快5點吧,公佈了以下的hw2
Me friend好像是10點多開始解題吧,一直想不出若用DP該如何解題。
最後用(類似)暴力法解題,又簡單又快速when lucky numbers<=774,746
(中午時在跟hw1不同的上網環境下, ”感覺”hw2 pro4的速度比hw1 pro4快很多,
這比較是不可靠的, 好像也沒啥意義).
(16日13點多或16日中午12點多,就有1556,774375,…等這些答案了)
在777 and 774746 之間的lucky numbers 共 1556 個。
第1541個 lucky number 是774375,無誤吧?
Algorithm Design and Analysis (NTU CSIE, Fall 2015) Homework #2
Due Time: 2015/10/30 (Fri.) 12:00
Problem 4 - Lucky Number (Programming)
Description
(30% + 6% bonus) In this problem, we say an integer n is a lucky number if:
‧ The integer n is divisible by 7.
‧ The decimal representation of n contains at least three digits 7.
‧ The decimal representation of n contains more digits 7 than digits 4.
For example, 777 and 774746 are lucky numbers; but 7771, 77, and
747474 are not. Can you tell
us how many lucky numbers are in range [l, r]?
Input Format
The first line contains an integer T indicating the total numb
er of test cases. Each test case contains
two integers l, r in one line.
‧ 1 T 100000
‧ 1 <= l <= r <= 10^18
Output Format
For each test case, please output an integer indicating how many lucky numbers
are in range [l, r] in one line.
Sample Input
3
1 10000
1 1000
1000 10000
Sample Output
5
1
4
Hint
‧ All lucky numbers in [1, 10000] are 777, 7077, 7707, 7770, 7777.
‧ There are two bonus tests (3 points each) in this problem.
The condition T <= 300 holds for the first 10 tests.
--
第8篇
--
Sent from my Android
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 106.104.66.155
※ 文章網址: https://www.ptt.cc/bbs/Diary/M.1445022095.A.8CB.html
※ 編輯: fun5566 (106.104.66.155), 10/17/2015 03:14:22
※ 編輯: fun5566 (106.104.66.155), 10/17/2015 03:20:43
推
10/17 12:35, , 1F
10/17 12:35, 1F
→
10/27 11:52, , 2F
10/27 11:52, 2F