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

这题有什么好算法吗?

Posted by Windwing at 2007-07-24 00:06:50 on Problem 1989
本人居然512ms……各位大牛又没有什么更好的方法,望不吝赐教哦~

#include<iostream>
using namespace std;

int main()
{
	int claim,zib;cin>>claim>>zib;
	int reader;
	bool* occur = new bool [zib+1];
	memset(occur,false,(zib+1)*sizeof(bool));
	int remain = zib,count = 1;
	bool oddflag = false;
	while(claim != 0)
	{
		cin>>reader;
		if(oddflag == occur[reader])
		{
			remain--;
			occur[reader] = !occur[reader];
		}
		if(remain == 0)
		{
			remain = zib;
			count++;
			oddflag = !oddflag;
		}
		claim--;
	}
	cout<<count<<endl;
	delete [] occur;
	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