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

实在受不了了?试了N个数,但不知道错在哪里。。谁能给个特殊数据??

Posted by wrp at 2009-11-22 19:44:53 on Problem 1032
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[31];
	int a,b,c;
	int i;
	double k;
		k=sqrt(double(n));
		a=k;
		b=n/a;
		c=n%a;
		for(i=0;i<a;i++)
			arr[i]=b-a/2+i;
		if(a%2==0)
		{
		   for(i=a/2;i<a;i++)
		   arr[i]++;
		   i=a/2;
           while(c>0&&i>0)
		   {
			   arr[--i]++;
			   c--;
		   }
		   while(c>0)
		   {i=a-1;
		    arr[i--]++;
			c--;
		   }
		}
		else 
		{
			i=a-1;
			while(c>0)
		   {arr[i--]++;
			c--;
		   }
		}
for(i=0;i<a;i++)
cout<<arr[i]<<" ";
cout<<endl;
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