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 |
O(N)时间算法400+ms,如何提高?/* * 3444.h * * Created on: Nov 20, 2010 * Author: shinjikun */ #include <cstdio> #include <iostream> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <map> using namespace std; int main() { int N, a[256]; while (scanf("%d", &N), N) { scanf("%d", a); for (int i = 1, idx = N >> 1, idxd = N; i < N; i++) { scanf("%d", a + idx); idx += idxd; if (idx > N) { idxd >>= 1; idx = idxd >> 1; } } for (int L = N >> 1; L; L >>= 1) { for (int i = 0; i < N; i += L << 1) { int m = a[i] + a[i + L]; int n = a[i] - a[i + L]; a[i] = m >> 1; a[i + L] = n >> 1; } } for (int i = 0; i < N; i++) printf("%d ", a[i]); putchar('\n'); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator