主题:[讨论]再次求助!答者50分!!!!!!!!!!!!!!!!!!!!!!!!!!
刚过桥DE米线
[专家分:0] 发布于 2011-09-29 12:26:00
【问题描述】
小K告诉了小新自己一天的安排:“8:30:30去超市”、“9:10:10去朋友家”、“10:20:10去…”、…。
小新看着复杂的安排表,晕了头,因为时间太混乱了,小K没有按照时间先后告诉他。于是他需要你帮助他把这些时间按照先后顺序输出。
【输入文件】
第一行一个整数N表示有多少个时间;
之后N行,每行空格隔开3个数字,依次分别表示时,分,秒。
【输出文件】
输出有N行,按照时间先后顺序输出所有的时间,输出的时候依然是每行3个空格隔开的数字,分别表示时,分,秒。
如果有2个时间是相同的,你仍然需要输出两次。
【样例输入】
4
3 22 21
3 21 22
3 22 22
3 21 21
【样例输出】
3 21 21
3 21 22
3 22 21
3 22 22
【数据范围】
对于70%的数据 N <= 1000;
对于100%的数据 N <= 15000;
保证输入格式为正常时间表示法,即时,分,秒都在[0,59]的范围内。
这道题不用高精度,但要用快数排序法
不然运行时间超过1秒,我不会,求教!!!
回复列表 (共14个回复)
沙发
幽灵密码 [专家分:3510] 发布于 2011-09-30 18:37:00
上网搜快速排序 字符串比较就行了
板凳
幽灵密码 [专家分:3510] 发布于 2011-10-01 12:30:00
[color=FF0000]DECLARE SUB Qsort (lo, hi)
RANDOMIZE TIMER
OPEN "Times.in" FOR INPUT AS #1
OPEN "Times.out" FOR OUTPUT AS #2
CLS
DIM SHARED n
INPUT #1, n
DIM SHARED a(n) AS DOUBLE
FOR i = 1 TO n
INPUT #1, x, y, z
a(i) = x * 3600 + y * 60 + z
NEXT i
Qsort 1, n
FOR i = 1 TO n
z = a(i) MOD 60
y = ((a(i) - z) MOD 3600) \ 60
x = (a(i) - y - z) \ 3600
PRINT #2, LTRIM$(STR$(x)); " " + LTRIM$(STR$(y)); " " + LTRIM$(STR$(z))
NEXT i
CLOSE
END
SUB Qsort (lo, hi)
i = lo
j = hi
t = a(FIX(RND * (hi - lo + 1)) + lo)
DO
WHILE a(i) < t
i = i + 1
WEND
WHILE a(j) > t
j = j - 1
WEND
IF i <= j THEN
SWAP a(i), a(j)
i = i + 1
j = j - 1
END IF
LOOP UNTIL i > j
IF i < hi THEN Qsort i, hi
IF j > lo THEN Qsort lo, j
END SUB[/color]
自己随便做了一个 你看看行不行
3 楼
刚过桥DE米线 [专家分:0] 发布于 2011-10-08 20:23:00
可以
谢谢唐铭康!
4 楼
刚过桥DE米线 [专家分:0] 发布于 2011-10-18 19:53:00
鄙视广告,我无语了,这么长
5 楼
wuhongqi2000 [专家分:30] 发布于 2011-11-14 17:56:00
NOT all that Mrs. Bennet, however, with the assistance of mens timberland boots her five daughters, could ask on the subject was sufficient to draw from her husband any satisfactory description of Mr. Bingley. They attacked him in various ways; with timberland 6 inch boots barefaced questions, ingenious suppositions, and distant surmises; but he eluded the skill of them all; and they were at last obliged to accept the second-hand intelligence of their timberland roll top neighbour Lady Lucas. Her report was highly favourable. Sir William had been delighted with him. He was quite young, wonderfully timberland roll top boot handsome, extremely agreeable, and, to crown the whole, he meant to be at the next assembly with a large party. Nothing could be more delightful! To be fond of dancing was a certain step towards timberland roll top boot falling in love; and very lively hopes of Mr. Bingley's heart were entertained.;If I can but see one of my daughters happily settled at Netherfield,; said Mrs. Bennet to her husband, ;and all the others Womens 14-Inch Premium Waterproof Boots equally well married, I shall have nothing to wish for.;In a few days Mr. Bingley returned Mr. Bennet's visit, and sat about ten minutes with him in his library. He had entertained shop timberland boots hopes of being admitted to a sight of the young ladies, of whose beauty he had heard much; but he saw only the father. The ladies were somewhat more fortunate, for they had the advantage timberland men boots of ascertaining, from an upper window, that he wore a blue coat and rode a black horse.An invitation to dinner was soon afterwards dispatched; and already had Mrs. Bennet planned the courses that were timberlands boots to do credit to her housekeeping, when an answer arrived which deferred it all. Mr. Bingley was obliged to be in town the following day, and consequently unable to accept the honour of their timberland boots on sale invitation, c. Mrs. Bennet was quite disconcerted. She could not imagine what business he could have in town so soon after his arrival in Hertfordshire; and she began to fear that he might cheap timberland boots be always flying about from one place to another, and never settled at Netherfield as he ought to be. Lady Lucas quieted her fears a little by starting the idea of his being gone to London only to timberland boots on sale get a large party for the ball; and a report soon followed that Mr. Bingley was to bring twelve ladies and seven gentlemen with him womens timberland boots to the assembly.
timberland 14 inch boots
timberland working boots
mens timberland boots zxj
DECLARE SUB Qsort (lo, hi)
RANDOMIZE TIMER
OPEN "Times.in" FOR INPUT AS #1
OPEN "Times.out" FOR OUTPUT AS #2
CLS
DIM SHARED n
INPUT #1, n
DIM SHARED a(n) AS DOUBLE
FOR i = 1 TO n
INPUT #1, x, y, z
a(i) = x * 3600 + y * 60 + z
NEXT i
Qsort 1, n
FOR i = 1 TO n
z = a(i) MOD 60
y = ((a(i) - z) MOD 3600) \ 60
x = (a(i) - y - z) \ 3600
PRINT #2, LTRIM$(STR$(x)); " " + LTRIM$(STR$(y)); " " + LTRIM$(STR$(z))
NEXT i
CLOSE
END
SUB Qsort (lo, hi)
i = lo
j = hi
t = a(FIX(RND * (hi - lo + 1)) + lo)
DO
WHILE a(i) < t
i = i + 1
WEND
WHILE a(j) > t
j = j - 1
WEND
IF i <= j THEN
SWAP a(i), a(j)
i = i + 1
j = j - 1
END IF
LOOP UNTIL i > j
IF i < hi THEN Qsort i, hi
IF j > lo THEN Qsort lo, j
END SUB
6 楼
王19991122 [专家分:70] 发布于 2011-11-18 17:13:00
cls
input n
dim a$(n)
for i=1 to n
input a$(i)
next i
for i=1 to n
for j=i to n
if a$(i)>a$(J) then swap a$(i),a$(j)
next j,i
for i=1 to n
print a$(i)
next i
7 楼
幽灵密码 [专家分:3510] 发布于 2011-11-18 23:54:00
[quote]cls
input n
dim a$(n)
for i=1 to n
input a$(i)
next i
for i=1 to n
for j=i to n
if a$(i)>a$(J) then swap a$(i),a$(j)
next j,i
for i=1 to n
print a$(i)
next i
[/quote]
如果不考虑时间问题用选择排序很好
但有时间限制,所以我用的是快速排序
8 楼
刚过桥DE米线 [专家分:0] 发布于 2011-11-22 19:42:00
对!同意
9 楼
刚过桥DE米线 [专家分:0] 发布于 2011-11-22 19:46:00
π=3.
1415926535 8979323846 2643383279 5028841971 6939937510 : 1
5820974944 5923078164 0628620899 8628034825 3421170679 : 2
8214808651 3282306647 0938446095 5058223172 5359408128 : 3
4811174502 8410270193 8521105559 6446229489 5493038196 : 4
4428810975 6659334461 2847564823 3786783165 2712019091 : 5
4564856692 3460348610 4543266482 1339360726 0249141273 : 6
7245870066 0631558817 4881520920 9628292540 9171536436 : 7
7892590360 0113305305 4882046652 1384146951 9415116094 : 8
3305727036 5759591953 0921861173 8193261179 3105118548 : 9
0744623799 6274956735 1885752724 8912279381 8301194912 : 10
9833673362 4406566430 8602139494 6395224737 1907021798 : 11
6094370277 0539217176 2931767523 8467481846 7669405132 : 12
0005681271 4526356082 7785771342 7577896091 7363717872 : 13
1468440901 2249534301 4654958537 1050792279 6892589235 : 14
4201995611 2129021960 8640344181 5981362977 4771309960 : 15
5187072113 4999999837 2978049951 0597317328 1609631859 : 16
5024459455 3469083026 4252230825 3344685035 2619311881 : 17
7101000313 7838752886 5875332083 8142061717 7669147303 : 18
5982534904 2875546873 1159562863 8823537875 9375195778 : 19
1857780532 1712268066 1300192787 6611195909 2164201989 : 20
3809525720 1065485863 2788659361 5338182796 8230301952 : 21
0353018529 6899577362 2599413891 2497217752 8347913151 : 22
5574857242 4541506959 5082953311 6861727855 8890750983 : 23
8175463746 4939319255 0604009277 0167113900 9848824012 : 24
8583616035 6370766010 4710181942 9555961989 4676783744 : 25
9448255379 7747268471 0404753464 6208046684 2590694912 : 26
9331367702 8989152104 7521620569 6602405803 8150193511 : 27
2533824300 3558764024 7496473263 9141992726 0426992279 : 28
6782354781 6360093417 2164121992 4586315030 2861829745 : 29
5570674983 8505494588 5869269956 9092721079 7509302955 : 30
3211653449 8720275596 0236480665 4991198818 3479775356 : 31
6369807426 5425278625 5181841757 4672890977 7727938000 : 32
8164706001 6145249192 1732172147 7235014144 1973568548 : 33
1613611573 5255213347 5741849468 4385233239 0739414333 : 34
4547762416 8625189835 6948556209 9219222184 2725502542 : 35
5688767179 0494601653 4668049886 2723279178 6085784383 : 36
8279679766 8145410095 3883786360 9506800642 2512520511 : 37
7392984896 0841284886 2694560424 1965285022 2106611863 : 38
0674427862 2039194945 0471237137 8696095636 4371917287 : 39
4677646575 7396241389 0865832645 9958133904 7802759009 : 40
9465764078 9512694683 9835259570 9825822620 5224894077 : 41
2671947826 8482601476 9909026401 3639443745 5305068203 : 42
4962524517 4939965143 1429809190 6592509372 2169646151 : 43
5709858387 4105978859 5977297549 8930161753 9284681382 : 44
6868386894 2774155991 8559252459 5395943104 9972524680 : 45
8459872736 4469584865 3836736222 6260991246 0805124388 : 46
4390451244 1365497627 8079771569 1435997700 1296160894 : 47
4169486855 5848406353 4220722258 2848864815 8456028506 : 48
0168427394 5226746767 8895252138 5225499546 6672782398 : 49
6456596116 3548862305 7745649803 5593634568 1743241125 : 50
1507606947 9451096596 0940252288 7971089314 5669136867 : 51
2287489405 6010150330 8617928680 9208747609 1782493858 : 52
9009714909 6759852613 6554978189 3129784821 6829989487 : 53
2265880485 7564014270 4775551323 7964145152 3746234364 : 54
5428584447 9526586782 1051141354 7357395231 1342716610 : 55
2135969536 2314429524 8493718711 0145765403 5902799344 : 56
0374200731 0578539062 1983874478 0847848968 3321445713 : 57
8687519435 0643021845 3191048481 0053706146 8067491927 : 58
8191197939 9520614196 6342875444 0643745123 7181921799 : 59
9839101591 9561814675 1426912397 4894090718 6494231961 : 60
5679452080 9514655022 5231603881 9301420937 6213785595 : 61
6638937787 0830390697 9207734672 2182562599 6615014215 : 62
0306803844 7734549202 6054146659 2520149744 2850732518 : 63
6660021324 3408819071 0486331734 6496514539 0579626856 : 64
1005508106 6587969981 6357473638 4052571459 1028970641 : 65
4011097120 6280439039 7595156771 5770042033 7869936007 : 66
2305587631 7635942187 3125147120 5329281918 2618612586 : 67
7321579198 4148488291 6447060957 5270695722 0917567116 : 68
7229109816 9091528017 3506712748 5832228718 3520935396 : 69
5725121083 5791513698 8209144421 0067510334 6711031412 : 70
6711136990 8658516398 3150197016 5151168517 1437657618 : 71
3515565088 4909989859 9823873455 2833163550 7647918535 : 72
8932261854 8963213293 3089857064 2046752590 7091548141 : 73
6549859461 6371802709 8199430992 4488957571 2828905923 : 74
2332609729 9712084433 5732654893 8239119325 9746366730 : 75
5836041428 1388303203 8249037589 8524374417 0291327656 : 76
1809377344 4030707469 2112019130 2033038019 7621101100 : 77
4492932151 6084244485 9637669838 9522868478 3123552658 : 78
2131449576 8572624334 4189303968 6426243410 7732269780 : 79
2807318915 4411010446 8232527162 0105265227 2111660396 : 80
10 楼
刚过桥DE米线 [专家分:0] 发布于 2011-11-22 19:46:00
哼,有我强!
我来回复