China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-10 15:57
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Use exhaustive search to solve an Olympiad math problem? View 936 Replies 9
Original Poster Posted 2008-11-17 17:35 ·  中国 广东 广州 番禺区 电信
初级用户
★★
Credits 156
Posts 73
Joined 2008-05-09 10:40
18-year member
UID 118210
Gender Male
Status Offline
The problem is like this: there is a four-digit number. The first digit is the number of 0s in this number, the second digit is the number of 1s in this number, the third digit is the number of 2s in this number, and the fourth digit is the number of 3s in this number. Find this number.
为自己是中国人而倍感骄傲
Floor 2 Posted 2008-11-17 19:28 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
- - ||| I actually didn't even understand what it means...
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 3 Posted 2008-11-17 19:47 ·  中国 福建 福州 连江县 电信
中级用户
★★
Credits 356
Posts 115
Joined 2004-07-27 00:00
22-year member
UID 29114
Gender Male
Status Offline
Floor 4 Posted 2008-11-17 20:14 ·  中国 重庆 沙坪坝区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Olympiad math problems probably shouldn't be done with exhaustive search, otherwise the Olympiad math teacher would harshly criticize you :)
Floor 5 Posted 2008-11-17 20:30 ·  中国 福建 福州 连江县 电信
中级用户
★★
Credits 356
Posts 115
Joined 2004-07-27 00:00
22-year member
UID 29114
Gender Male
Status Offline
"The first digit is the number of 0s in this number", so the first digit definitely cannot be 0, otherwise it's a contradiction.
Floor 6 Posted 2008-11-17 21:06 ·  中国 安徽 马鞍山 联通
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
Not sure whether the units digit is the first digit, or the thousands digit is the first digit.
Windows 一键还原
http://www.yjhy.com
Floor 7 Posted 2008-11-18 00:14 ·  中国 广东 广州 番禺区 电信
初级用户
★★
Credits 156
Posts 73
Joined 2008-05-09 10:40
18-year member
UID 118210
Gender Male
Status Offline
Reply #3 is correct, but it doesn't seem to have been calculated with P.
The first digit cannot be 0, otherwise it would be a three-digit number.
Also, that's if "the first digit" in the problem means counting from the left. If the first digit means counting from the right, then I don't know what the answer is. Still hope it can be done with P
为自己是中国人而倍感骄傲
Floor 8 Posted 2008-11-18 08:49 ·  中国 安徽 马鞍山 联通
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
If the first digit is counted from the right, then it's 0.003
Windows 一键还原
http://www.yjhy.com
Floor 9 Posted 2008-11-18 15:19 ·  中国 福建 福州 连江县 电信
中级用户
★★
Credits 356
Posts 115
Joined 2004-07-27 00:00
22-year member
UID 29114
Gender Male
Status Offline
The first digit means counting from the left. Answers: 1210 2020
If the first digit is counted from the right, then 0202 0121. If the first digit cannot be 0, otherwise it would be a three-digit number, then there is no solution.
Below is for counting the first digit from the left
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
for /l %%a in (0,1,3) do (
for /l %%b in (0,1,3) do (
for /l %%c in (0,1,3) do (
for /l %%d in (0,1,3) do (
set n=0
for /l %%e in (0,1,3) do (
set m%%e=0
if %%a==%%e set /a m%%e+=1
if %%b==%%e set /a m%%e+=1
if %%c==%%e set /a m%%e+=1
if %%d==%%e set /a m%%e+=1
)
if !m0!==%%a set /a n+=1
if !m1!==%%b set /a n+=1
if !m2!==%%c set /a n+=1
if !m3!==%%d set /a n+=1
if !n!==4 echo %%a%%b%%c%%d
))))
ENDLOCAL
pause
Floor 10 Posted 2008-11-18 15:56 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Shouldn't the outermost for start from 0?
Forum Jump: