ææ95è³07å¹´çææé¢ç®
æä½ çé®ç®±åè¯ææå°±å¯ä»¥ç»ä½ äº
æ8MBå¤ä¸ç¹
ç»åä¾åï¼
æ®åç»
é¢ç®ä¸è§
é¢ç®å称 å¥å¦é 纪念ååç» å®æè
çé离 Hanoiåå¡é®é¢
ä»£å· scholar group escape hanoi
è¾å
¥æ件 scholar.in group.in escape.in hanoi.in
è¾åºæ件 scholar.out group.out escape.out hanoi.out
æ¶é 1ç§ 1ç§ 1ç§ 1ç§
(2007å¹´11æ17æ¥ 3å°æ¶å®æ)
说æï¼
1. æ件åï¼ç¨åºååè¾å
¥è¾åºæ件åï¼å¿
须使ç¨å°å
2. C/C++ä¸å½æ°main()çè¿åå¼ç±»åå¿
é¡»æ¯intï¼ç¨åºæ£å¸¸ç»ææ¶çè¿åå¼å¿
é¡»æ¯0ã
3. å
¨å½ç»ä¸è¯æµæ¶éç¨çæºå¨åèé
置为ï¼CPU 2.0GHzï¼å
å256Mã
1ï¼å¥å¦é
(scholar.pas/c/cpp)
ãé®é¢æè¿°ã
æå°å¦æè¿å¾å°äºä¸ç¬èµå©ï¼æç®æ¿åºå
¶ä¸ä¸é¨å为å¦ä¹ æ绩ä¼ç§çå5åå¦çåå¥å¦éãææ«ï¼æ¯ä¸ªå¦çé½æ3é¨è¯¾çæ绩ï¼è¯æãæ°å¦ãè±è¯ãå
ææ»åä»é«å°ä½æåºï¼å¦æ两个åå¦æ»åç¸åï¼åæè¯ææ绩ä»é«å°ä½æåºï¼å¦æ两个åå¦æ»ååè¯ææ绩é½ç¸åï¼é£ä¹è§å®å¦å·å°çåå¦æå¨åé¢ï¼è¿æ ·ï¼æ¯ä¸ªå¦ççæåºæ¯å¯ä¸ç¡®å®çã
ä»»å¡ï¼å
æ ¹æ®è¾å
¥ç3é¨è¯¾çæ绩计ç®æ»åï¼ç¶åæä¸è¿°è§åæåºï¼æåææå顺åºè¾åºå5åå¦ççå¦å·åæ»åã注æï¼å¨å5ååå¦ä¸ï¼æ¯ä¸ªäººçå¥å¦éé½ä¸ç¸åï¼å æ¤ï¼ä½ å¿
é¡»ä¸¥æ ¼æä¸è¿°è§åæåºãä¾å¦ï¼å¨æ个æ£ç¡®çæ¡ä¸ï¼å¦æå两è¡çè¾åºæ°æ®ï¼æ¯è¡è¾åºä¸¤ä¸ªæ°ï¼å¦å·ãæ»åï¼æ¯ï¼
7 279
5 279
è¿ä¸¤è¡æ°æ®çå«ä¹æ¯ï¼æ»åæé«ç两个åå¦çå¦å·ä¾æ¬¡æ¯7å·ã5å·ãè¿ä¸¤ååå¦çæ»åé½æ¯279ï¼æ»åçäºè¾å
¥çè¯æãæ°å¦ãè±è¯ä¸ç§æ绩ä¹åï¼ï¼ä½å¦å·ä¸º7çå¦çè¯ææ绩æ´é«ä¸äºãå¦æä½ çå两åçè¾åºæ°æ®æ¯ï¼
5 279
7 279
åæè¾åºé误å¤çï¼ä¸è½å¾åã
ãè¾å
¥ã
è¾å
¥æ件scholar.inå
å«n+1è¡ï¼
第1è¡ä¸ºä¸ä¸ªæ£æ´æ°nï¼è¡¨ç¤ºè¯¥æ ¡åå è¯éçå¦ç人æ°ã
第2å°n+1è¡ï¼æ¯è¡æ3个ç¨ç©ºæ ¼éå¼çæ°åï¼æ¯ä¸ªæ°åé½å¨0å°100ä¹é´ã第jè¡ç3个æ°åä¾æ¬¡è¡¨ç¤ºå¦å·ä¸ºj-1çå¦ççè¯æãæ°å¦ãè±è¯çæ绩ãæ¯ä¸ªå¦ççå¦å·æç
§è¾å
¥é¡ºåºç¼å·ä¸º1~nï¼æ°å¥½æ¯è¾å
¥æ°æ®çè¡å·å1ï¼ã
æç»çæ°æ®é½æ¯æ£ç¡®çï¼ä¸å¿
æ£éªã
ãè¾åºã
è¾åºæ件scholar.outå
±æ5è¡ï¼æ¯è¡æ¯ä¸¤ä¸ªç¨ç©ºæ ¼éå¼çæ£æ´æ°, ä¾æ¬¡è¡¨ç¤ºå5åå¦ççå¦å·åæ»åã
ãè¾å
¥è¾åºæ ·ä¾1ã
scholar.in scholar.out
6
90 67 80
87 66 91
78 89 91
88 99 77
67 89 64
78 89 98 6 265
4 264
3 258
2 244
1 237
ãè¾å
¥è¾åºæ ·ä¾2ã
scholar.in scholar.out
8
80 89 89
88 98 78
90 67 80
87 66 91
78 89 91
88 99 77
67 89 64
78 89 98 8 265
2 264
6 264
1 258
5 258
ãéå¶ã
50%çæ°æ®æ»¡è¶³ï¼åå¦ççæ»æ绩åä¸ç¸å
100%çæ°æ®æ»¡è¶³ï¼6<=n<=300
2ï¼çºªå¿µååç»
(group.pas/c/cpp)
ãé¢ç®æè¿°ã
å
æ¦å¿«å°äºï¼æ ¡å¦çä¼è®©ä¹ä¹è´è´£æ°å¹´æä¼ç纪念ååæ¾å·¥ä½ã为使å¾åå æä¼çåå¦æè·å¾ç纪念åä»·å¼ç¸å¯¹åè¡¡ï¼ä»è¦æè´æ¥ç纪念åæ ¹æ®ä»·æ ¼è¿è¡åç»ï¼ä½æ¯ç»æå¤åªè½å
æ¬ä¸¤ä»¶çºªå¿µåï¼å¹¶ä¸æ¯ç»çºªå¿µåçä»·æ ¼ä¹åä¸è½è¶
è¿ä¸ä¸ªç»å®çæ´æ°ã为äºä¿è¯å¨å°½éççæ¶é´å
åå®ææ纪念åï¼ä¹ä¹å¸æåç»çæ°ç®æå°ã
ä½ çä»»å¡æ¯åä¸ä¸ªç¨åºï¼æ¾åºææåç»æ¹æ¡ä¸åç»æ°æå°çä¸ç§ï¼è¾åºæå°çåç»æ°ç®ã
ãè¾å
¥ã
è¾å
¥æ件group.inå
å«n+2è¡ï¼
第1è¡å
æ¬ä¸ä¸ªæ´æ°wï¼ä¸ºæ¯ç»çºªå¿µåä»·æ ¼ä¹åçä¸éã
第2è¡ä¸ºä¸ä¸ªæ´æ°nï¼è¡¨ç¤ºè´æ¥ç纪念åçæ»ä»¶æ°ã
第3~n+2è¡æ¯è¡å
å«ä¸ä¸ªæ£æ´æ°pi (5 <= pi <= w)ï¼è¡¨ç¤ºæ对åºçºªå¿µåçä»·æ ¼ã
ãè¾åºã
è¾åºæ件group.outä»
ä¸è¡ï¼å
å«ä¸ä¸ªæ´æ°ï¼å³æå°çåç»æ°ç®ã
ãè¾å
¥è¾åºæ ·ä¾ã
group.in group.out
100
9
90
20
20
30
50
60
70
80
90 6
ãéå¶ã
50%çæ°æ®æ»¡è¶³ï¼1 <= n <= 15
100%çæ°æ®æ»¡è¶³ï¼1 <= n <= 30000, 80 <= w <= 200
3ï¼å®æè
çé离
(escape.pas/c/cpp)
ãé®é¢æè¿°ã
æ¶éçæ尤迪å®éå¿ååï¼ä»èåäºæå¤ç²¾çµï¼çé¢æ·±èå¨æµ·åºçå¨è¿¦æä¼å¾ååãå®æè
å¨ä¸å°¤è¿ªå®ç交éä¸ééäºå´æï¼è¢«å°å¨ä¸ä¸ªèèç大å²ä¸ã为äºææ»å®æè
ï¼å°¤è¿ªå®å¼å§å¯¹è¿ä¸ªèå²æ½åï¼è¿åº§å²å¾å¿«å°±ä¼æ²ä¸å»ãå°é£æ¶ï¼å²ä¸çææ人é½ä¼éé¾ãå®æè
çè·æ¥é度为17m/sï¼ä»¥è¿æ ·çé度æ¯æ æ³é离èå²çãåºå¹¸çæ¯å®æè
æ¥æéªçæ³æ¯ï¼å¯å¨1så
移å¨60mï¼ä¸è¿æ¯æ¬¡ä½¿ç¨éªçæ³æ¯é½ä¼æ¶èéæ³å¼10ç¹ãå®æè
çéæ³å¼æ¢å¤çé度为4ç¹/sï¼åªæå¤å¨åå°ä¼æ¯ç¶ææ¶æè½æ¢å¤ã
ç°å¨å·²ç¥å®æè
çéæ³åå¼Mï¼ä»æå¨çåå§ä½ç½®ä¸å²çåºå£ä¹é´çè·ç¦»Sï¼å²æ²æ²¡çæ¶é´Tãä½ çä»»å¡æ¯åä¸ä¸ªç¨åºå¸®å©å®æè
计ç®å¦ä½å¨æççæ¶é´å
é离èå²ï¼è¥ä¸è½éåºï¼åè¾åºå®æè
å¨å©ä¸çæ¶é´å
è½èµ°çæè¿è·ç¦»ã注æï¼å®æè
è·æ¥ãéªçæä¼æ¯æ´»å¨å以ç§(s)为åä½ï¼ä¸æ¯æ¬¡æ´»å¨çæç»æ¶é´ä¸ºæ´æ°ç§ãè·ç¦»çåä½ä¸ºç±³(m)ã
ãè¾å
¥ã
è¾å
¥æ件escape.inä»
ä¸è¡ï¼å
æ¬ç©ºæ ¼éå¼çä¸ä¸ªéè´æ´æ°M, S, Tã
ãè¾åºã
è¾åºæ件escape.outå
å«ä¸¤è¡ï¼
第1è¡ä¸ºå符串âYesâæâNoâï¼åºå大å°åï¼ï¼å³å®æè
æ¯å¦è½é离èå²ã
第2è¡å
å«ä¸ä¸ªæ´æ°ã第ä¸è¡ä¸ºâYesâï¼åºå大å°åï¼æ¶è¡¨ç¤ºå®æè
é离èå²çæçæ¶é´ï¼ç¬¬ä¸è¡ä¸ºâNoâï¼åºå大å°åï¼æ¶è¡¨ç¤ºå®æè
è½èµ°çæè¿è·ç¦»ã
ãè¾å
¥è¾åºæ ·ä¾1ã
escape.in escape.out
39 200 4 No
197
ãè¾å
¥è¾åºæ ·ä¾2ã
escape.in escape.out
36 255 10 Yes
6
ãéå¶ã
30%çæ°æ®æ»¡è¶³ï¼1 <= T <= 10, 1 <= S <= 100
50%çæ°æ®æ»¡è¶³ï¼1 <= T <= 1000, 1 <= S <= 10000
100%çæ°æ®æ»¡è¶³ï¼1 <= T <= 300000, 0 <= M <= 1000, 1 <= S <= 108.
4ï¼Hanoiåå¡é®é¢
(hanoi.pas/c/cpp)
ãé®é¢æè¿°ã
ç»å®AãBãCä¸æ ¹è¶³å¤é¿çç»æ±ï¼å¨Aæ±ä¸æ¾æ2n个ä¸é´æåçåçï¼å
±æn个ä¸åç尺寸ï¼æ¯ä¸ªå°ºå¯¸é½æ两个ç¸åçåçï¼æ³¨æè¿ä¸¤ä¸ªåçæ¯ä¸å åºåçï¼ä¸å¾ä¸ºn=3çæ
å½¢ï¼ãç°è¦å°è¿äºåç移å°Cæ±ä¸ï¼å¨ç§»å¨è¿ç¨ä¸å¯æ¾å¨Bæ±ä¸æåãè¦æ±ï¼
ï¼1ï¼æ¯æ¬¡åªè½ç§»å¨ä¸ä¸ªåçï¼
ï¼2ï¼AãBãCä¸æ ¹ç»æ±ä¸çåçé½è¦ä¿æä¸å°ä¸å¤§ç顺åºï¼
ä»»å¡ï¼è®¾An为2n个åçå®æä¸è¿°ä»»å¡æéçæå°ç§»å¨æ¬¡æ°ï¼å¯¹äºè¾å
¥çnï¼è¾åºAnã
ãè¾å
¥ã
è¾å
¥æ件hanoi.in为ä¸ä¸ªæ£æ´æ°nï¼è¡¨ç¤ºå¨Aæ±ä¸æ¾æ2n个åçã
ãè¾åºã
è¾åºæ件hanoi.outä»
ä¸è¡ï¼å
å«ä¸ä¸ªæ£æ´æ°, 为å®æä¸è¿°ä»»å¡æéçæå°ç§»å¨æ¬¡æ°Anã
ãè¾å
¥è¾åºæ ·ä¾1ã
hanoi.in hanoi.out
1 2
ãè¾å
¥è¾åºæ ·ä¾2ã
hanoi.in hanoi.out
2 6
ãéå¶ã
对äº50%çæ°æ®ï¼1<=n<=25
对äº100%çæ°æ®ï¼1<=n<=200
ãæ示ã
设æ³å»ºç«Anä¸An-1çéæ¨å
³ç³»å¼ã
温馨提示:答案为网友推荐,仅供参考