File tree Expand file tree Collapse file tree 2 files changed +48
-2
lines changed
Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Original file line number Diff line number Diff line change 4848 font-size : 13px ;
4949}
5050
51- .run-button {
51+ .run-button ,
52+ .random-button {
5253 padding : 6px 16px ;
53- background : # 0e639c ;
5454 color : white;
5555 border : none;
5656 border-radius : 4px ;
5959 transition : background 0.2s ;
6060}
6161
62+ .run-button {
63+ background : # 0e639c ;
64+ }
65+
6266.run-button : hover {
6367 background : # 1177bb ;
6468}
6569
6670.run-button : active {
6771 background : # 0d5a8c ;
6872}
73+
74+ .random-button {
75+ background : # 6a4c93 ;
76+ }
77+
78+ .random-button : hover {
79+ background : # 7d5ba6 ;
80+ }
81+
82+ .random-button : active {
83+ background : # 5a3d7a ;
84+ }
Original file line number Diff line number Diff line change @@ -50,6 +50,33 @@ export default function InputPanel({
5050 }
5151 } ;
5252
53+ const generateRandom = ( ) => {
54+ // 随机课程数量 3-8
55+ const num = Math . floor ( Math . random ( ) * 6 ) + 3 ;
56+
57+ // 生成随机 DAG(有向无环图)
58+ const prereqs : number [ ] [ ] = [ ] ;
59+ const edgeCount = Math . floor ( Math . random ( ) * ( num * 2 ) ) + 1 ;
60+ const existingEdges = new Set < string > ( ) ;
61+
62+ for ( let i = 0 ; i < edgeCount ; i ++ ) {
63+ // 确保 from > to 来避免环
64+ const to = Math . floor ( Math . random ( ) * ( num - 1 ) ) ;
65+ const from = Math . floor ( Math . random ( ) * ( num - to - 1 ) ) + to + 1 ;
66+ const key = `${ from } -${ to } ` ;
67+
68+ if ( ! existingEdges . has ( key ) ) {
69+ existingEdges . add ( key ) ;
70+ prereqs . push ( [ from , to ] ) ;
71+ }
72+ }
73+
74+ setNumCourses ( num . toString ( ) ) ;
75+ setPrerequisites ( JSON . stringify ( prereqs ) ) ;
76+ setError ( null ) ;
77+ onSubmit ( num , prereqs ) ;
78+ } ;
79+
5380 return (
5481 < div className = "input-panel" >
5582 < div className = "input-group" >
@@ -75,6 +102,9 @@ export default function InputPanel({
75102 < button className = "run-button" onClick = { handleSubmit } >
76103 运行
77104 </ button >
105+ < button className = "random-button" onClick = { generateRandom } >
106+ 🎲 随机生成
107+ </ button >
78108 </ div >
79109 ) ;
80110}
You can’t perform that action at this time.
0 commit comments