Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:同一解法In Reply To:同一解法 Posted by:zhangfeifei at 2010-08-23 21:02:40 再提一点,就是不必交换,只需赋值。注意到运行到第 i 次时,交换 i 和 i 位置上的数值。因为 i 是从 1 开始逐个往上累加的, 所以 i 交换过后根本就没用过。所以就直接对后面的赋值。 int getRes(int n) { int i,sum=0; for(i=1;i<=n;i++) { if(num[i] != i) { sum ++; num[index[i]] = num[i]; index[num[i]] = index[i]; } } return sum; } 但,还是 47 ms,不知道怎地。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator