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

2456K内存AC了

Posted by gfedcba at 2009-01-12 14:53:45 on Problem 2081 and last updated at 2009-01-12 16:32:16
// Accept 2456K 16MS 
// 哪位大牛可以在内存2450K的情况下做到0MS,请教一下

#include <iostream>
using namespace std;

const int K = 500000;
int  list[K];

// have相当于一个hash,将某个数做为下标
// mask进行位的俺码计算,用每一个bit来标示该数是否已经存在,以节省内存
// 当然,如果用bool也能做到只用一个bit来标示~

char have[376600];
const int mask[8]={0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80};


int main()
{
	bool a = true;
	cout<<sizeof(a)<<endl;
	int n;
	int i;

	memset(list, 0 ,sizeof(list));
	list[0] = 0;
	have[0] |= mask[0];

	for (i=1; i<=K-1; i++)
	{
		list[i]  = list[i-1] - i;
		if (list[i]>0 && !(have[list[i]/8]&mask[list[i]%8]))
		{
			have[list[i]/8] |= mask[list[i]%8];
		}                     
		else
		{
			list[i] = list[i-1] + i;
			have[list[i]/8] |= mask[list[i]%8];
		}
	}
    
	while (scanf("%d", &n) && n!=-1)
	{
		printf("%d\n",list[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