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

晕,1到13算完才0.3m还说超时!!!

Posted by robertzhang at 2007-05-14 11:57:40 on Problem 1012
直接看源代码,中间我自己加了测时间的

#include <iostream>
#include <vector>
#include <ctime>
using namespace std;

int Choose(int k);
bool Check(int m,int k);

int main()
{
	int k;
	vector<int> result;
	while(cin>>k)
	{		
		if(k==0)
			break;	
		result.push_back(k);
	}
	clock_t start,finish;
	start=clock();
	for(unsigned int i=0;i<result.size();i++)
	{			
		cout<<Choose(result[i])<<endl;
	}
	finish=clock();
	cout<<"Time take : "<<((double)(finish-start))/CLOCKS_PER_SEC<<endl;
	return 0;
}

int Choose(int k)
{
	int m=k+1;
	while(true)
	{
		if(Check(m,k))
			return m;
		else
			m++;
	}
}

bool Check(int m,int k)
{
	int pos=0;
	for(int i=0;i<k;i++)
	{
		pos=(m+pos)%(2*k-i);
		if(pos<=k && pos!=0)
			return false;
		if(pos==0)
			pos=2*k-i-1;
		else
			pos--;
	}
	return true;
}

算完0.328m

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