Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

O(N)时间算法400+ms,如何提高?

Posted by Shinjikun at 2010-11-20 17:38:16 on Problem 3444
/*
 * 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator